javascript - How will the stack of this function will look like? -
when following:
function makeaddfunction(amount) { function add(number) { return number + amount; } return add; } var addtwo = makeaddfunction(2); var addfive = makeaddfunction(5); alert(addtwo(1) + addfive(1));
will each instance of makeaddfunction
have separate stack or of them use same stack? , order of variables entering , leaving stack matter?
each function call creates new function
(-context). answer quickly, yes have separate "stacks" in terms of ecmascripts execution contexts
.
i'm not sure mean "the order of variables entering , leaving stack".
ecmascript contexts (objects). there stack of execution contexts called in order. after 1 context finished, parent context continues run until it's finished (and forth). principle lasts long there contextes if not, global context
gets attention again.
Comments
Post a Comment