|
theMonths = new MakeArray(12)
// load array with English month names
function MakeArray(n) {
this[0] = "anuary"
this[1] = "February"
this[2] = "March"
this[3] = "April"
this[4] = "May"
this[5] = "June"
this[6] = "July"
this[7] = "August"
this[8] = "September"
this[9] = "October"
this[10] = "November"
this[11] = "December"
this.length = n
return this
}
這個(gè)是Java Script Bible 4th Edition上面的一段代碼.
這種this的用法 是怎么個(gè)意思?Javascript的this還有匿名obj的作用?
這樣的用法只能限于函數(shù)內(nèi)部吧
拋出異常的愛 寫道
這樣就可以在別的地方用
代碼
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
的確看到一個(gè)類似的用法
代碼
// create basic array
theMonths = new MakeArray(12)
如果this[]的用法,表示this是一個(gè)array object
那么
代碼
this.length = n
這個(gè)似乎讓this又成為了一個(gè)擁有一個(gè)array object 和一個(gè) int 變量的 object了
this于是看上去像某個(gè)匿名class的object了
是否可以這樣理解呢?
JavaScript技術(shù):this[] 指的是什么內(nèi)容 討論,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。