开发者

Difficulty with MooTools Class.extend

Consider the following code:

var Widget = new Class({
       Implements: [Options],
       options: {
          "name" : "BaseWidget"
       },
       initialize: function(options) {
          alert("Options are: " + JSON.stringify(options)); //alerts "Options are: undefined"
          this.setOptions(options);
          alert("My options are: " + JSON.stringify(this.options)); //alerts "My options are: { 'name' : 'BaseWidget' }"开发者_开发技巧
       },
       getName: function() {
          return this.options.name;   
       }
});

var LayoutWidget = Widget.extend({    
       initialize: function() {
          this.parent({ "name" : "Layout" });
       }
});

alert(new LayoutWidget().getName()); //alerts "BaseWidget"

I am having difficulty in determining why the argument passed in the "this.parent()" call in "initialize" function of LayoutWidget is coming through as "undefined" in the initialize function of Widget.

I am using MooTools 1.2.2. Would somebody be able to point me in the right direction?


check this: http://www.jsfiddle.net/F4hTS/

slight difference in form.

var Widget = new Class({
    Implements: [Options],
    options: {
        "name" : "BaseWidget"
    },
    initialize: function(options) {
        alert("Options are: " + JSON.stringify(options)); //alerts "Options are: undefined"
        this.setOptions(options);
        alert("My options are: " + JSON.stringify(this.options)); //alerts "My options are: { 'name' : 'BaseWidget' }"
    },
    getName: function() {
        return this.options.name;   
    }
});

Widget.LayoutWidget = new Class({   
    Extends: Widget,
    initialize: function(options) {
        this.parent(options);
    }
});

alert(new Widget.LayoutWidget({ "name" : "Layout" }).getName()); //alerts "Layout"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜