var Shape = Class.create(new Element("div", {
"class": "shape"
}), {
//constructor of Shape
initialize: function () {
}
})
Shape 类继承自 Element 的实例,我想知道的是,如果可以的话,如何在 Shape 的构造函数中引用这个实例 ?
最佳答案
使用它来引用 Shape
构造函数内的 Element
实例:
this.constructor.prototype
或者,您可以这样做(因为形状从元素继承没有意义):
var Shape = (function() {
var elem = new Element("div", {
"class": "shape"
});
return Class.create({
initialize: function() {
//refer to elem here
}
});
})();
关于javascript - 在类的构造函数中获取类的父类的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13212375/