出錯:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var obj = { //少var 亦會出錯 a : { a : function (){ } , b : ( function (){ console.log( obj ); // 出錯 })() }, b : ( function (){ console.log( obj ); // 出錯 })() } |
正常:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | var obj = {} obj.a = { a : '123' , b : '456' , c : function (){ return this .a + this .b ; } , init : function (){ console.log( this ) ; } } obj.a.init() ; |
var obj = { //少var 亦會出錯
a : {
a : function(){
} ,
b : (function(){
console.log( obj )
})()
},
b : (function(){
console.log( obj ) // 出錯
})()
}
正常:
var obj = {}
obj.a = {
a : '123' ,
b : '456' ,
c : function(){
return this.a + this.b ;
} ,
init : function(){
console.log( this ) ;
}
}
obj.a.init() ;
http://stackoverflow.com/questions/3455405/how-to-remove-a-key-from-a-javascript-object
刪除一個物件的key
delete thisIsObject[key];
沒有留言:
張貼留言