现在的位置: 首页 > 综合 > 正文

JS继承

2013年12月12日 ⁄ 综合 ⁄ 共 270字 ⁄ 字号 评论关闭
<script>
function Person (name, age) {
    this.name = name;
    this.age = age;
}

Person.prototype.sayHi = function (){
    alert(this.name+'=='+ this.age)
}

function student(name,age) {
    Person.apply(this, [name, age])
}
student.prototype = Person.prototype;
var stu = new student("zhang1",221);
stu.sayHi()
</script>

抱歉!评论已关闭.