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 :

  1. why chrome , firefox act differently on ? -additional 1 : wich 1 right ? -
  2. 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.

scroll conditionally defining function


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -