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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -