Akiq2016/blog

what-new-function-do

Opened this issue · 0 comments

I read webpack/tapable recently, it's news to me when I found many new Function() there. Cause I mainly use function declaration and expression. So I check when we need it.

new Function() generate an anoymous function. It can accepts any number arguments, function args go first, function body is last, and all arguments are string. That's said, we can use new Function() to generate function dynamicly.

It performs a little difference in runtime, it's scope chain only has function inner variable object + global object which means it drops the lexical environment.