<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>
javascript继承
最新推荐文章于 2024-01-11 22:13:27 发布