function Person(name,age){ //定義一個類,人類 this.name=name //名字 this.age=age //年齡 this.sayhello=function(){alert("hello")} }
function Print(){ //顯示類的屬性 this.funcName="Print" this.show=function(){ var msg=[] for(var key in this){ if (typeof(this[key])!="function") msg.push([key,":",this[key]].join("")) } alert(msg.join("/n")) } }
function Student(name,age,grade,school){ //學(xué)生類 Person.apply(this,arguments) Print.apply(this,arguments) this.grade=grade //年級 this.school=school //學(xué)校 }
var p1=new Person("jake",10) p1.sayhello()
var s1=new Student("tom",13,6,"清華小學(xué)") s1.show() s1.sayhello() alert(s1.funcName) </script>