Created
June 28, 2013 15:43
-
-
Save SIvaCoHan/5885663 to your computer and use it in GitHub Desktop.
js 闭包问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function obj(){ | |
return { | |
init: function(params){ | |
//bla bla bla | |
}, | |
add: function(x,y){ | |
//blab bla | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
严格意义上来说,此函数不算闭包,因为这样写内部函数并没有使用内部函数以外作用域的变量等,改进下。
function obj(params,x,y){
}
这个时候在调用 init 和 add 的时候就算闭包了。
但是 js 中只要是函数,都可以看做是闭包的。