当前位置: 首页 > 图文教程 > 网络编程 > Javascript > this[] 指的是什么内容 讨论

Javascript
js操作ajax返回的json的注意问题!
javascript document.compatMode兼容性
jquery 锁定弹出层实现代码
Jquery+CSS 创建流动导航菜单 Fluid Navigation
js下用层来实现select的title提示属性
JSON 学习之JSON in JavaScript详细使用说明
jquery实现的超出屏幕时把固定层变为定位层的代码
jQuery 性能优化手册 推荐
javascript Firefox与IE 替换节点的方法
ext combox 下拉框不出现自动提示,自动选中的解决方法
json-lib出现There is a cycle in the hierarchy解决办法
判断控件是否已加载完成的代码
javascript for循环设法提高性能
js 表格拖拽效果实例代码 (IE only)
javascript 命名规则 变量命名规则
js 面向对象的技术创建高级 Web 应用程序
User agent字符串将成为用户真正的隐私问题
JS教程:JavaScript全半角转换
JS教程:Chrome对数组的sort方法优化
WEBJX收集非常有用的免费的Javascript开发工具

Javascript 中的 this[] 指的是什么内容 讨论


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 32 ::
收藏到网摘: n/a

代码
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了
是否可以这样理解呢?