javascript - Javscript closure return Function -
function funca(){ var name = "jack"; console.log(name); return function(){ name = name + " plus"; console.log(name); }; } var funb = funca(); funb() //result: "jack" "jack plus"
i comfuse why run var funb = funca();
compile "jack"
? why return sentance didn't work?but must wait until second time compile??
it works, try run this:
function funca(){ var name = "jack"; console.log(name); return function(){ name = name + " plus"; console.log(name); }; } var funb = funca(); funb();
Comments
Post a Comment