Do nested function declarations create a new object for each call?

Is anonymous function re-written Fooin memory every time it is called Foo()?

function Foo(product)
{
    return function(n) {
        return n * product;
    }
}

I am more or less interested in implementing V8, in particular, because I do not see anything in this regard in the specification (unless I miss something that I probably have).

I am a bit confused about memory management as usage productrefers to a closure that returns; however, this does not necessarily mean that the inner function must be recreated with the closure instance (theoretically), since you can still .bind()without losing the closure value.

+4
source share
3

, Function:

function Foo(product)
{
    return function(n) {
        return n * product;
    }
}

var a = Foo(2);
var b = Foo(2);

alert(a === b);    // alerts false

: http://jsfiddle.net/wc5Lv/


, , , javascript .

+3

. ECed, 5ed, , . http://es5.imtqy.com/#x13, " "

, Function, , , . product .

+2

Source: https://habr.com/ru/post/1541842/


All Articles