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)部吧
拋出異常的愛 寫道
這樣就可以在別的地方用
代碼
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了
是否可以這樣理解呢?
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了
是否可以這樣理解呢?
相關(guān)文章
JS實(shí)現(xiàn)頁面長時(shí)間不操作退出到登錄頁面的示例代碼
這篇文章主要介紹了JS實(shí)現(xiàn)頁面長時(shí)間不操作退出到登錄頁面的示例代碼,通過在head標(biāo)簽中引入jquey和頁面長時(shí)間不操作的js頁面,結(jié)合實(shí)例代碼講解的非常詳細(xì),需要的朋友可以參考下2024-03-03
js構(gòu)建二叉樹進(jìn)行數(shù)值數(shù)組的去重與優(yōu)化詳解
這篇文章主要給大家介紹了關(guān)于js構(gòu)建二叉樹進(jìn)行數(shù)值數(shù)組的去重與優(yōu)化的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03
javascript設(shè)計(jì)模式 – 橋接模式原理與應(yīng)用實(shí)例分析
這篇文章主要介紹了javascript設(shè)計(jì)模式 – 橋接模式,結(jié)合實(shí)例形式分析了javascript橋接模式基本概念、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
JavaScript實(shí)現(xiàn)的encode64加密算法實(shí)例分析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的encode64加密算法,實(shí)例分析了javascript處理encode64編碼針對字符串加密的技巧,非常簡潔實(shí)用,需要的朋友可以參考下2015-04-04

