Sencha Touch v2.3,ExtJS v4.1.0。
创建新类时,为什么this
要从constructor
方法中返回?
示例(来自下面的链接):
var Person = new Ext.Class({
name: 'Mr. Unknown',
constructor: function(name) {
this.name = name;
return this; // <-- HERE. Why????
},
walk: function(steps) {
alert(this.name + ' is walking ' + steps + ' steps');
}
});
var jacky = new Person('Jacky');
jacky.walk(10); // alerts "Jacky is walking 10 steps"