白开水

海阔凭鱼跃,天高任鸟飞!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

<script type="text/javascript">

/*//继承的第一种方式:对象冒充
function parent(username){
    this.username=username;
    
    this.sayhello=function(){
        alert(this.username)
        }
    }
function child(username,password){
    //下面三行代码最关键
    this.method=parent;

    this.method(username);
    this.password=password;
    
    this.sayword=function(){
        alert(this.password);
        }
    }
var parent= new parent("zhangsan");
var child=new child("lishi","123");
parent.sayhello();
child.sayhello();
child.sayword();*/

/*//继承第二种方法:call方法方式,function 对象的中方法
function test(str){
    alert(this.name+str);
    }
var object=new Object();
object.name="zhangsan";

//this.call相当于调用test函数
test.call(object,"ningkangchun");//将object赋给了this*/
//使用原形链(prototype chain)方法实现对象的继承

</script>

posted on 2012-02-08 11:50  baikaishui1989  阅读(214)  评论(0编辑  收藏  举报