Difficulty with MooTools Class.extend
Posted
by Erin Drummond
on Stack Overflow
See other posts from Stack Overflow
or by Erin Drummond
Published on 2010-06-18T05:35:12Z
Indexed on
2010/06/18
5:43 UTC
Read the original article
Hit count: 315
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?
© Stack Overflow or respective owner