🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ /* let n = 1; let x = { n: 2, y: (function (n) { n = n || 3; return function (m) { m = m || 4; this.n += m++; n += ++m; console.log(n); } })(window.n)//=>把window下n这个属性的值赋值给私有变量n (window中没有n这个属性,所以传递的是undefined) }; let z = x.y; x.y(5); //10 z(6);//18 console.log(n, x.n, window.n);*/ //1 7 NaN ~~~ ![](https://img.kancloud.cn/7f/6f/7f6ff81fd4df307ca7dc37bb459e2705_1768x1006.png) ~~~ let n = 1, obj = {n: 2}; let fn = obj.fn = (function () { this.n += n; n *= 2; return function (m) { n -= 5 + (++m); this.n += n--; console.log(n); } })(obj.n); fn(3); obj.fn(4); console.log(n, obj.n, window.n); ~~~