我写了两个函数,我认为应该没啥区别,但是执行结果却大有区别。哪位高手帮我解释一下,这两种函数调用为什么会不同?
function close(){
var myline=100;
return(function(){
return(myline++);
});
}
console.log(close()); //console output:// funciton()
console.log(close()()); //console output:// 100
console.log(close()()); //console output:// 100
//closure example
var copyclose=(function(){
var myline=300;
return(function(){
return myline++;
});
}());
console.log(copyclose()); //console output:// 300
console.log(copyclose()); //console output:// 301
console.log(copyclose); //console output:// function()
杨魅力