我有一个使用Path2D对象绘制三角形的代码:
var path = new Path2D();
path.moveTo(elem[i], elem[i+1]);
path.lineTo(elem[i+2], elem[i+3]);
path.lineTo(elem2[i], elem2[i+1]);
path.lineTo(elem[i], elem[i+1]);
path.closePath();
但我也在这个对象中添加新属性:
path.topLine = elem;
path.bottomLine = elem2;
然后我修改隐藏类指针。这是我的问题: 我上面有很多这样的对象 - 它们会有相同的隐藏类,还是会为每个对象创建一个新类?
我应该创建某种"构造函数"第一λ
例如:
var path = function(elem, elem2, i){
this.prototype = new Path2D;
this.topLine = elem;
this.bottomLine = elem2;
this.i = i;
}
然后:
var path1 = path(someArrayOrObject,someObjectOrArray, someInteger);