<p>继承类</p>
模拟类的继承功能
<script type ="text/javascript">
Object.prototype.ext = function(parObject) {
//parObject表示父类对象
for (var i in parObject) {
this[i] = parObject[i];
}
}
//父类
function Person(P_name, P_age) {
this.name = P_name;
this.age = P_age;
this.Say = function() { alert(this.name + this.age); }
}
//子类
function Student(p_id) {
this.id = p_id;
}
//我们希望stu1可能通用person下的属性和方法
var stu1 = new Student(3);
stu1.ext(new Person('zhangsan', 30));
stu1.Say();
</script>
模拟类的继承功能
<script type ="text/javascript">
Object.prototype.ext = function(parObject) {
//parObject表示父类对象
for (var i in parObject) {
this[i] = parObject[i];
}
}
//父类
function Person(P_name, P_age) {
this.name = P_name;
this.age = P_age;
this.Say = function() { alert(this.name + this.age); }
}
//子类
function Student(p_id) {
this.id = p_id;
}
//我们希望stu1可能通用person下的属性和方法
var stu1 = new Student(3);
stu1.ext(new Person('zhangsan', 30));
stu1.Say();
</script>