//无参数的
(function(){
alert('hello');
})();
//有参数的
(function(name){
alert('Hello ' + name);
})('world');
这个闭包有什么用呢?一眼望去就是括号围着,局部变量想跑也不出来到处捣乱,这是其中一个主要用途,当然了,封装一些javascript库也离不开它。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn