<script>var name = heheh;var init =(function(){var name = abc;functioncallName(){
console.log(name);}returnfunction(){callName();}}())var initZhang =(function(){var name =123;functioncallName(){
console.log(name);}returnfunction(){callName();}}())</script>
通过写一个立即执行函数加上闭包return一个函数的写法 让变量私有化 ,
虽然全局和 init 和 initZhang 里面都有 name 这个 变量,但是它们互不影响。
连续调用函数
var wang ={
smoke :function(){
console.log('Smoking!');returnthis;},
drink :function(){
console.log('Drinking');returnthis;},
perm :function(){
console.log('cool!');returnthis;}}
wang.smoke().drink().perm();