Javascript function as a variable? -


here code example mozilla javascript closures:

function makefunc() {   var name = "mozilla";   function displayname() {     alert(name);   }   return displayname; }  var myfunc = makefunc(); myfunc(); 

why return inner function displayname() variable displayname, is, without parentheses?

return displayname()

  1. invoke alert @ line var myfunc set ,
  2. return undefined.

return displayname (without parentheses) returns function whereas former (with parentheses) invokes function , returns whatever function returns. function displayname doesn't have explicit return statement implied return type undefined.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -