//声明一个父类
function Person(name){
this.name=name;
this.age=age;
this.say=function(){
alert("我叫"+this.name);
}
}
//声明一个子类
function Student(){
this.no=no;
this.study=function(){
alert("我在学习!");
}
}
// 通过循坏,将父类对象的所有属性和方法,全部赋给子类对象
Object.prototype.extend=function(parent){
for(var i in parent){
this[i].parent[i];
}
}
var p=new Person("张三",12);
var s=new Student("1234567");
//子类对象调用这个扩展方法
s.extend()
console.log(s);
//声明父类
function Person(name,age){
this.name=name;
this.age=age;
this.say=function(){
alert("我叫"+this.name);
}
}
//声明子类
function Student(no){
this.no=no;
this.study=function(){
alert("我在学习!我叫"+this.name+"今年"+this.age");
}
}
//将父类对象赋给子类的prototype
Student.prototype=new Person("张三",14);
//拿到子类对象时,就会将父类对象的所有属性和方法,添加到__proto__
var s=new Student();
s.study();
function Person(name,age){
this.name=name;
this.age=age;
this.say=function(){
alert("我叫"+this.name);
}
}
function Student(no,name,age){
this.no=no;
this.study=function(){
alert("我在学习!");
}
//将父类函数的this,指向为子类函数的this
Person.call(this,name,age);
}
var s=new Student(12,"张三",24);
console.log(s);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有