匿名函数/构造函数中的关键字
this keyword inside anonymous function/constructor
在某种程度上,我知道代码中发生了什么,只是为了澄清我的疑问,我已经发布了这个问题
JavaScriptPoint = function (x, y) //Here anonymous constructor is define
{
this.x = x;
this.y = y;
}
var points=[]
points.push(new Point(centerX + radius * Math.sin(angle),centerY - radius * Math.cos(angle))); //object is created and push in the array
和访问点数组的值,我可以写点[I].x?
是,检查这个
var Point = function (x, y) //Here anonymous constructor is define
{
this.x = x;
this.y = y;
}
var points = [];
points.push(new Point(2,5));
points.push(new Point(3,11));
points.push(new Point(9,1));
for(var i = 0; i <points.length; i++){
console.log(points[i].x);
console.log(points[i].y);
};
正确,您可以使用索引i访问对象,然后对对象解引用以访问其属性/成员
var Point = function (x, y)
{
this.x = x;
this.y = y;
}
var points = [];
points.push(new Point(1, 2));
var point = points[0];
alert(point.x == point[0].x);
相关文章:
- ES6构造函数返回基类的实例
- 使用Google Visualization动态调用构造函数
- javascript中对象构造函数中的var属性与this.properties
- 理解typescript中的构造函数接口
- 为什么构造函数不是构造函数
- 如果在构造函数中有“返回”,则在 JavaScript 中的新运算符中做了什么
- 拦截对构造函数的调用
- 使用闭包共享构造函数参数
- 文本表示法VS.构造函数,用于在JavaScript中创建对象
- 从js引擎的角度来看闭包和构造函数是如何工作的
- 如何使用此从对象访问构造函数
- 为什么在构造函数函数中使用此关键字
- 正在检测是否在构造函数内部使用了新关键字
- 为什么实例没有't在没有prototype关键字的情况下继承添加到构造函数的属性
- 为什么函数在构造函数中声明时不使用new关键字
- 该关键字是构造函数中的窗口对象
- 从构造函数中引用Javascript实例变量而不使用'this'关键字
- 匿名函数/构造函数中的关键字
- JavaScript:关于构造函数**新**关键字的问题
- return和new关键字构造函数模式的区别是什么?