<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
(function() {
function people(name) {
this._name = name;
}
function student(name) {
this._name = name;
}
//为原型对象添加say方法
people.prototype.say = function() {
alert("bassclass" + this._name);
}
//拷贝所有方法到student
student.prototype = new people();
//获取子类实例方法对象
var stSay = student.prototype.say;
//重写父类方法
student.prototype.say = function() {
//调用基类方法,就用子类实例方法传this
stSay.call(this);
alert("subclass" + this._name);
}
//赋给全局属性,暴露接口
window.student = student;
}());//后面加“()”表示立即执行,外面套一层函数,是外部不能访问。
var st = new student("lin");
st.say();
</script>
</head>
<body>
</body>
</html>