Dojo 中定义和继承class
面向对象,定义Class
dojo里如何定义Class:
dojo.declare("Customer",null,{ constructor:function(name){ this.name = name; }, say:function(){ alert("Hello " + this.name); }, getDiscount:function(){ alert("Discount is 1.0"); }});var customer1 = new Customer("Mark");customer1.say(); dojo.declare("VIP",Customer,{ getDiscount:function(){ alert("Discount is 0.8"); }});var vip = new VIP("Mark");vip.say();vip.getDiscount();dojo.declare("VIP",Customer,{ getDiscount:function(){ this.inherited(arguments); //this.inherited("getDiscount",arguments); }});dojo.declare("Customer",null,{ say:function(){ alert("Hello Customer"); }, getDiscount:function(){ alert("Discount in Customer"); }});dojo.declare("MixinClass",null,{ say:function(){ alert("Hello mixin"); }, foo:function(){ alert("foo in MixinClass"); }});dojo.declare("VIP",[Customer,MixinClass],{});var vip = new VIP();vip.getDiscount();vip.foo();vip.say();//输出"Hello MixinClass"