//命名空间 //利用闭包防止变量污染
1 var name = ‘bcd‘; 2 var init = (function () { 3 var name = ‘abc‘; 4 function callName() { 5 console.log(name) 6 } 7 return function () { 8 callName(); 9 } 10 }()); 11 init(); 12 var li = { 13 wife1 : {name:"l"}, 14 wife2 : {name:"x"}, 15 wife3 : {name:"w"}, 16 wife4 : {name:"z"}, 17 sayWife : function (num) { 18 return this[‘wife‘ + num] 19 } 20 }
//对象枚举
var obj = { name: ‘li‘, age: 12, height: 175, weight: 75 }; //遍历 枚举 for (var i in obj) { console.log(i); }
原文地址:https://www.cnblogs.com/punisher999/p/12229365.html
时间: 2024-10-14 18:46:22