MooTools Class.extend 的困难
考虑以下代码:
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"
我很难确定为什么在 LayoutWidget 的“initialize”函数中的“this.parent()”调用中传递的参数在 Widget 的初始化函数中显示为“未定义”。
我正在使用 MooTools 1.2.2。有人能指出我正确的方向吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查一下: http://www.jsfiddle.net/F4hTS/
形式上略有不同。
check this: http://www.jsfiddle.net/F4hTS/
slight difference in form.