internet explorer - Javascript: Inconsistency when assigning a named function to a variable (named function expression) -



internet explorer - Javascript: Inconsistency when assigning a named function to a variable (named function expression) -

can explain difference in behaviour between net explorer , firefox in regards below:

var mynamespace = (function () { var exposed = {}; exposed.myfunction = function myfunction () { homecoming "works!"; } console.log(myfunction()); // ie: "works!" // firefox: referenceerror: myfunction not defined console.log(exposed.myfunction()); // ie: "works!" // ff: "works!" homecoming exposed; })(); console.log(mynamespace.myfunction()); // ie: "works!" // ff: "works!"

in net explorer method allows me phone call function within namespace function using either myfunction() or exposed.myfunction().

outside namepsace function can utilize mynamespace.myfunction()

in firefox, results same exception of bare named function phone call not work.

should work? if shouldn't, why not?

if should known bug?

to prevent false information:

ie has problem named function expressions have. name of function should available inside function. specification:

the identifier in functionexpression can referenced within functionexpression's functionbody allow function phone call recursively. however, unlike in functiondeclaration, identifier in functionexpression cannot referenced , not impact scope enclosing functionexpression.

where functionexpression defined as:

functionexpression :      function identifieropt ( formalparameterlistopt ) { functionbody }

but in ie, instead of making name available within function, creates 2 different function objects, 1 assigned variable , other name gave function. next yield false in ie (and throw error in other browsers):

exposed.myfunction === myfunction;

it's known bug , if have code (older versions of) ie, improve avoid named function expressions.

related question:

detachevent not working named inline functions named function expressions in ie, part 2

javascript internet-explorer firefox cross-browser

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -