this[]指的是什么内容讨论
什么 内容 this 讨论
2023-06-13 09:13:55 时间
代码
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
}
这个是Java Script Bible 4th Edition上面的一段代码.
这种this的用法 是怎么个意思?javascript的this还有匿名obj的作用?
这样的用法只能限于函数内部吧
抛出异常的爱 写道
这样就可以在别的地方用
代码
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
的确看到一个类似的用法
代码
// create basic array
theMonths = new MakeArray(12)
如果this[]的用法,表示this是一个array object
那么
代码
this.length = n
这个似乎让this又成为了一个拥有一个array object 和一个 int 变量的 object了
this于是看上去像某个匿名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
}
这个是Java Script Bible 4th Edition上面的一段代码.
这种this的用法 是怎么个意思?javascript的this还有匿名obj的作用?
这样的用法只能限于函数内部吧
抛出异常的爱 写道
这样就可以在别的地方用
代码
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
的确看到一个类似的用法
代码
// create basic array
theMonths = new MakeArray(12)
如果this[]的用法,表示this是一个array object
那么
代码
this.length = n
这个似乎让this又成为了一个拥有一个array object 和一个 int 变量的 object了
this于是看上去像某个匿名class的object了
是否可以这样理解呢?
相关文章
- js对象中什么是可枚举性(enumerable)?[通俗易懂]
- 大型企业选择低代码的主要原因是什么?
- python中imread什么意思_imwrite函数
- 在Oracle中,实例恢复和介质恢复的区别是什么?
- 什么是入侵检测系统?有哪些分类?
- 优思学院:《改变世界的机器・精益生产之道》是什么著作?
- CDR2023中文版强悍来袭!CorelDRAW 2023有什么新内容?
- PostgreSQL索引失效会发生什么
- Java程序运行时,数据都保存到什么地方详解编程语言
- 搜索引擎是什么?
- CMS内容管理系统是什么?
- 学Linux,展翅翱翔职场(学linux做什么工作)
- Linux:用它来改变世界(Linux用来做什么)
- ?MSSQL中最佳索引策略的探索(mssql 用什么索引)
- MySQL 中 TRY 指什么(mysql中try的意思)
- 使用命令行来操作Redis(用什么运行redis命令)
- 用Redis存储什么内容(什么内容放redis)
- Redis在商城中的表现如何提升顾客体验(商城中redis有什么用)
- Redis存储什么内容(redis里面存什么)
- 都有什么Oracle一张表的所有内容(oracle 一张表里)