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()
- invoke alert @ line
var myfunc
set , - 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
Post a Comment