工厂模式虽然解决了创建多个对象的问题,但是并没有解决识别对象从属的问题.因为都属于object.因此出现了构造函数
//构造函数名称首字母大写是规范
function Box(name,age){
this.name=name;
this.age=age;
this.run=function(){
return this.name+'--'+this.age;
}
}
var box1=new Box('gao',23);
var box2=new Box('zhang',20);
console.log(box1 instanceof box)//还从属于box
console.log(box2 instanceof box)//还从属于box 通过构造函数我们实例化出来的对象能够知道对象不仅仅从属于Object,这也就是构造函数和工厂模式的区别
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body>...
jQuery 插件——jqueryrotate,它可以实现旋转效果。jqueryrotate 支持所有主流浏览器,包括 IE6。如果提示方法不存在,可能是你的Jquery版本过低或者过高。基本语法:$('#img').rotate(90);//旋转90度其他的参数:参数类型说明默认值...
//构造函数 function Box(name,age){ this.name=name; this.age=age; this.run=function(){ return this.name+'--'+this.age; } } var&nbs...
//我们创建每个函数默认都有一个prototype(原型)属性,这个属性是一个对象 //1.我是普通的构造方法,我的属性叫实例属性,我的方法叫实例方法 /* function Box(name,age){ this.name=name; this.age=age; this.run...