Calling JavaScript function with the syntax (0, myFunction)() -



Calling JavaScript function with the syntax (0, myFunction)() -

i'm new in javascript, found syntax (0, myfunction)() phone call anonymous functions on javascript, don't know means 0 before anonymous function, don't know if instead of 0 can utilize 1 or 2, etc.

basically question difference between phone call function myfuntion() or (0, myfunction)(). function in global context.

here example.

var object = {} object.foo = function(){}

the difference between phone call function

(0,object.foo)();

or

object.foo();

you can rewrite both calls next equivalents:

object.foo.call(null); // (0,object.foo)(); object.foo.call(foo); // object.foo();

as can see, difference "binding" of this within called function; utilize of (0, something)(); considered cryptic , should avoided in professional code base.

javascript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -