function Parent(username){ this.username = username; this.hello = function(){ console.log(this.username); } }
Parent.prototype.sayMorning = function(){ console.log('good morning ' + this.username); }
function Child(username,password){ Parent.call(this,username);
this.password = password; this.world = function(){ console.log(this.password); } }
var parent = new Parent("zhangsan"); var child = new Child("lisi","123456"); parent.hello(); parent.sayMorning(); child.hello(); child.world(); // child.sayMorning(); 通过prototype 添加的方法和属性,不能用来继承
|