1 window.addEvent('domready',function(){ 2 /* 3 新建一个Person的类,类上有 name属性和sayHello方法; 4 */ 5 var Person= new Class({ 6 initialize: function(name){ 7 this.name = name; 8 }, 9 sayHello:function(){ 10 console.log('hello,my name is '+this.name); 11 } 12 13 }); 14 15 //新建一个Sperman类,继承Person上的属性和方法 16 var Sperman=new Class({ 17 Extends:Person, 18 initialize:function(name,age){ 19 this.parent(name); 20 this.age=age; 21 }, 22 }); 23 //给Dog扩展新方法 sayWang 24 Sperman.implement({ 25 sayAll:function(){ 26 console.log(this.name+' is '+this.age+' years old...'); 27 } 28 }); 29 var Sperman=new Sperman('ollie',27); 30 Sperman.sayHello();//consolo.log hello,my name is ollie 31 32 Sperman.sayAll();//console.log ollie is 27 years old... 33 });