//字面量的形式创建原型对象
/*
function Box(){}
Box.prototype={
'name':'gao',
age:23,
fun:function(){
return this.name+'--'+this.age;
}
}
var box1=new Box();
console.log(box1.age)
console.log(box1.constructor)
*/
//1.使用字面量后constructor会指向Object,因为Box.prototype={}这种写法创建了一个新的对象导致.
//解决方式如下:
function Box(){}
Box.prototype={
constructor:Box,
'name':'gao',
age:23,
fun:function(){
return this.name+'--'+this.age;
}
}
var box1=new Box();
console.log(box1.age)
console.log(box1.constructor)
//2.原型对象不仅仅在自定义对象中可以使用,内置的引用类型都可以使用,并且本身页使用了原型
var box2=[1,15,9,8,6,12];
console.log(Array.prototype.sort());
//3.给原型增加方法
String.prototype.addstring=function(){
return this+'-Hello!';
}
console.log('China'.addstring()); <!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="utf-8"> </head> <bo...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> ...
jQuery 插件——jqueryrotate,它可以实现旋转效果。jqueryrotate 支持所有主流浏览器,包括 IE6。如果提示方法不存在,可能是你的Jquery版本过低或者过高。基本语法:$('#img').rotate(90);//旋转90度其他的参数:参数类型说明默认值...
工厂模式虽然解决了创建多个对象的问题,但是并没有解决识别对象从属的问题.因为都属于object.因此出现了构造函数//构造函数名称首字母大写是规范 function Box(name,age){ this.name=name; this.age=age; this.run=funct...
//我们创建每个函数默认都有一个prototype(原型)属性,这个属性是一个对象 //1.我是普通的构造方法,我的属性叫实例属性,我的方法叫实例方法 /* function Box(name,age){ this.name=name; this.age=age; this.run...