大鸟的学习乐园
路漫漫其修远兮,吾将上下而求索
posts - 26,comments - 27,trackbacks - 0
function Parent(name){
this.name = name;
}
Parent.prototype.say = function(){
alert(this.name);
}
var parent = new Parent("wwwwww");
parent.say();
function Child(name,password){
Parent.call(this,name);
this.password = password;
}
Child.prototype = new Parent();
Child.prototype.sayword = function(){
alert(this.password);
}
var child = new Child("111111","222222222");
child.sayword();

////用call实现继承
function Parent(name){
this.name = name;
this.say = function(){
alert(this.name );
}
}
function Child(name,password){
Parent.call(this,name);
this.password = password;
}
var child = new Child("123123","sssss");
child.say();
*/
//用APPLY实现继承
/*
function Parent(name){
this.name= name;
this.say= function(){
alert(this.name);
}
}
function Child(name,password){
Parent.apply(this,new Array(name));
this.password = password;
this.sayworld = function(){
alert(this.password + this.name);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi","123456");
parent.say();
child.say();
child.sayworld();




posted on 2011-05-28 09:58 大鸟 阅读(206) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: