原型链 继承

        function F1() {}
        F1.prototype.sayHello = function(){
            alert("I'm a superman.");
        }

        function f2(skill){
            this.skill = skill;
        }
        f2.prototype = new F1();

        var david = new f2("fly");
        david.sayHello();

 继承

function Person(name, age){
    this.name = name;
    this.age = age;
}
Person.prototype.sayHello = function(){
    alert('hello');
}

function Tom(id){
    this.id = id;
}
Tom.prototype = new Person('tom', '12');
var tom = new Tom('123456');


tom.id;
tom.sayHello();

 

posted @ 2015-03-03 17:45  幹掉上帝  阅读(83)  评论(0编辑  收藏  举报