JavaScript实现类的继承
下面是常用的js类继承的方式,我们继承一下上篇文章中的Person类:
function Person(name, age, email){this.name = name;this.age = age;this._email = email;}function _Person_show_me(){alert('我叫' + this.name + ',我' + this.age + '岁了,我的email是' + this._email);}Person.prototype.show_me = _Person_show_me;function Student(name, age, email, score){Person.call(this, name, age, email);this.score = score;}function _Student_show_score(){alert("我的分数是:" + this.score);}Student.prototype = new Person();Student.prototype.show_score = _Student_show_score;var he = new Student('小何', 28, 'baijun.he@163.com', 80);he.show_me();he.show_score();