//字面量的形式创建原型对象
/*
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()); 由于工作需要长期使用Ajax,一个页面重复的AJAX请求太多,于是封装起来,只需要编写回调函数/* ------------- 使用方法: 1.ajaxrequest()函数执行准备的参数(1.请求地址2.发送数据字符串拼接3.type值可选get/post4.回调函数名称) exam...
WebSql的原理是浏览器集成了sqllite数据库,Js操作,浏览器协助完成,没有多复杂。<!-- 三个核心方法  ...
捕捉模式从DOM最顶层一直到最后一层,冒泡正好相反,具体运行以下实例测试.<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="...
<!-- 三个核心方法 openDatabase:这个方法使用现有数据库或创建...
工厂模式虽然解决了创建多个对象的问题,但是并没有解决识别对象从属的问题.因为都属于object.因此出现了构造函数//构造函数名称首字母大写是规范 function Box(name,age){ this.name=name; this.age=age; this.run=funct...
在es5的时候变量只能通过+号拼接,es6种允许将变量放在大括号之中。有点类似php和c#对字符串的操作。 <script type="text/javascript"> &n...