Javascript Function-Pointer Assignment

前端 未结 11 1062
广开言路
广开言路 2020-12-04 12:05

Consider this javascript code:

var bar = function () { alert(\"A\"); }
var foo = bar;
bar = function () { alert(\"B\"); };
foo();

When runn

11条回答
  •  失恋的感觉
    2020-12-04 12:40

    For each FunctionDeclaration f in code, in source text order do:

    Let fn be the Identifier in FunctionDeclaration f.

    Let fo be the result of instantiating FunctionDeclaration f as described in Clause 13.

    Let funcAlreadyDeclared be the result of calling env’s HasBinding concrete method passing fn as the argument.

    If funcAlreadyDeclared is false, call env’s CreateMutableBinding concrete method passing fn and configurableBindings as the arguments.

    References

    • ECMAScript-5: Section 10.5

提交回复
热议问题