Javascript Function Object Body
If in Javascript functions is objects(key/value pairs), can I think that function body stored in some property of function object?
Solution 1:
Yes, you could think of this that way. This was more formalized in the ES6 spec:
Function code is source text that is parsed to supply the value of the
[[ECMAScriptCode]]
and[[FormalParameters]]
internal slots (see 9.2) of an ECMAScript function object.
and
ECMAScript function objects have the additional internal slots listed in Table 27
[...]
[[ECMAScriptCode]]
Parse Node The root parse node of the source text that defines the function’s body.
An "internal slot" is basically like a property that cannot be accessed from user code, it cannot only be accessed by the runtime itself.
So yes, the function object has a reference to the (parsed) code of its body in some way.
Post a Comment for "Javascript Function Object Body"