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

    }
})

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

4

1 回答 1

1

http://jsfiddle.net/r585d/

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

this.constructor.prototype

或者,您可以这样做(因为从元素继承形状没有意义):

var Shape = (function() {
    var elem = new Element("div", {
        "class": "shape"
    });
    return Class.create({
        initialize: function() {
            //refer to elem here    
        }
    });
})();
于 2012-11-03T19:03:30.470 回答