this[] 指的是什么內(nèi)容 討論
更新時(shí)間:2007年03月24日 00:00:00 作者:
代碼
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)部吧
拋出異常的愛(ài) 寫(xiě)道
這樣就可以在別的地方用
代碼
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
的確看到一個(gè)類(lèi)似的用法
代碼
// 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了
是否可以這樣理解呢?
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)部吧
拋出異常的愛(ài) 寫(xiě)道
這樣就可以在別的地方用
代碼
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
的確看到一個(gè)類(lèi)似的用法
代碼
// 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了
是否可以這樣理解呢?
相關(guān)文章
微信小程序?qū)崿F(xiàn)同時(shí)上傳多張圖片
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)同時(shí)上傳多張圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02微信小程序?qū)崙?zhàn)篇之購(gòu)物車(chē)的實(shí)現(xiàn)代碼示例
本篇文章主要介紹了微信小程序?qū)崙?zhàn)篇之購(gòu)物車(chē)的實(shí)現(xiàn)代碼示例,詳細(xì)的介紹了購(gòu)物車(chē)的功能實(shí)現(xiàn),具有一定的參考價(jià)值,有興趣的可以了解一下2017-11-11