//定义一个构造函数
function People(name,age){
this.name=name;
this.age=age;
this.dothings=function(){
retrun this.name+this.age;
}
}
var people1 = new People("panda1",25);
var people2 = new People("panda2",26);
alert(people1.name==people2.name) //false
People.prototype={
constructor:People //强制指向People
name:"panda",
age:25,
dothings:function(){
return this.name+this.age;
}
}
var people = new People();
alert(people.constructor); //function People(){}
//声明一个构造函数
function People(){}
//在原型添加属性
People.prototype.name="panda";
People.prototype.age=25;
people.prototype.dothings=function(){
return this.name+this.age;
}
//实例化构造函数
var people1 = new People();
var people2 = new People();
alert(people1.name==perople2.name) //true 因为都是原型里的方法,它们的地址是共享的,大家都来自同一地方。
var people = new People(); people.name="bear"; alert(people.name); //bear alert(people1.name); //panda
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有