javascript继承

来源:互联网 发布:手持数据终端i6200s 编辑:程序博客网 时间:2024/05/22 14:00
<script>    function Person(first,last) {        this.first = first;        this.last = last;    };    Person.prototype = {        fullName:function () {            return this.last+'.'+this.first;        }    };    function Student(first,last,id) {        Person.call(this,first,last);     //call是function才有的    所以Person.prototype.call(this,first,last); 是不行的  也就是说call不能指向Person 的 prototype        this.id = id;    };    Student.prototype = new Person();//    Student.prototype = {//       getid:function () {//           return this.id;//       }//    };    //如果这样写就会有问题    Student.prototype.getid = function () {        return this.id;    };    var dinwan = new Student("din","wan","21");    alert(dinwan.fullName());    alert(dinwan.getid());</script>
0 0