var Shape = Class.create(new Element("div", {
    "class": "shape"
}), {
    //constructor of Shape
    initialize: function () {

    }
})


Shape类继承自Element的实例,我想知道的是,如果可以的话,如何在Shape的构造函数中引用此实例?

最佳答案

http://jsfiddle.net/r585d/

使用它来引用Element构造函数中的Shape实例:

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/

10-12 03:38
查看更多