require(["dojo/_base/declare", "dojo/_base/lang"], function(declare, lang){ var A = declare(null, { m1: function(){ /*...*/ }, m2: function(){ /*...*/ }, m3: function(){ /*...*/ }, m4: function(){ /*...*/ }, m5: function(){ /*...*/ } }); va
require(["dojo/_base/declare", "dojo/_base/lang"], function(declare, lang){
var A = declare(null, {
m1: function(){ /*...*/ },
m2: function(){ /*...*/ },
m3: function(){ /*...*/ },
m4: function(){ /*...*/ },
m5: function(){ /*...*/ }
});
var B = declare(A, {
m1: function(){
// declare 方法也保证了其中定义法的方法与类本身兼容,如我们可以直接调用
// this.inherited(arguments)
return this.inherited(arguments); // 调用 A.m1
}
});
B.extend({
m2: function(){
// 类的 extend 方法也保证了其中定义法的方法与类本身兼容
return this.inherited(arguments); // 调用 A.m2
}
});
lang.extend(B, {
m3: function(){
// lang 的 extend 方法不能保证其中定义法的方法与类本身兼容,所以要加入方法“m3”本身
return this.inherited("m3", arguments); // 调用 A.m3
});
var x = new B();
declare.safeMixin(x, {
m4: function(){
// declare 的 safeMixin 能保证其中定义法的方法与类本身兼容
return this.inherited(arguments); // 调用 A.m4
}
});
lang.mixin(x, {
m5: function(){
// 普通的 mixin 不能保证兼容
return this.inherited("m5", arguments); // 调用 A.m5
});
});
