Search

2/09/2009

||: default operator


>>> YAHOO
ReferenceError: YAHOO is not defined source=with(_FirebugCommandLine){YAHOO\n};
>>> YAHOO = YAHOO || {}
ReferenceError: YAHOO is not defined
>>> YAHOO = {}
Object
>>> YAHOO.foo = YAHOO.foo || {}
Object

要 initial YAHOO 只能用

if(typeof YAHOO == 'undefined' || !YAHOO){
var YAHOO = {};
}

要 initial YAHOO 裡面的 property 可以用比較快的方法

YAHOO.foo = YAHOO.foo || {}

沒有留言: