Javascript scope weirdness, function and browser -
i thought doing this:
var = function () {};
and
function () {}
was same thing in js, functions supposed "first class object".
today learned in firefox code :
var test = true; if (test) { function () { alert("foo"); } } else { function () { alert("bar"); } } what();
display foo, , weird reason chrome display bar... why [number one] ? doing :
var test = true, what; if (test) { = function() { alert("foo"); } } else { = function () { alert("bar"); } } what();
solved problem.. why [number two]? can try out http://jsfiddle.net/7cbs5gr7/ here
[abstract] have 2 questions :
- why chrome , firefox act differently on ? -additional 1 : wich 1 right ? -
- why setting function explicitly in var solved problem ?
functions can conditionally defined using either //function statements// (an allowed extension ecma-262 edition 3 standard) or function constructor. please note such function statements no longer allowed in es5 strict. additionally, feature not work consistently cross-browser, should not rely on it.
Comments
Post a Comment