Advertisement
Advertisement

新足迹

 找回密码
 注册
新足迹 › 门户 › AI 相关› 查看内容

自己写一小段js代码 关于self executing function的everything

2011-7-6 10:27| 发布者: o2h2o | 查看: 1721| 原文链接

写自己的library 的时候 貌似可以这样用
保护了变量 也能export 函数去外部
欢迎大牛斧正

var out=6;
(function(){
    var inside=5;
    alert(out); //showing 6
    function show(){
            alert("show function")
    }
// use this to export inside function to outside
    var show2=this.show2=function(){

            alert("show 2");
    }
})();
alert(typeof inside) //undefined

show2(); //yes, can be called
show(); //undefined

[ 本帖最后由 o2h2o 于 2011-7-6 10:56 编辑 ]
Advertisement
Advertisement


Advertisement
Advertisement
返回顶部