//字面量的形式创建原型对象
/*
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> <meta charset="utf-8" /> <title>获取mac地址</title> </head&g...
代码1:<!--代码开始--> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script>...
通过FormData对象可以组装一组用 XMLHttpRequest发送请求的键/值对。它可以更灵活方便的发送表单数据,因为可以独立于表单使用。如果你把表单的编码类型设置为multipart/form-data ,则通过FormData传输的数据格式和表单通过submit() 方法传输的数据格式相同...
二期项目中生成的简历二维码是使用canvs生成的,微信浏览器中不能识别二维码,只能扫码。懒的换phpqrcode,于是转canvs。//设置一个url var url = "{yun:}$config.sy_weburl{/yun}/mingli/index....
查看文章前你需要了解以下2点://1.this指向的是windows对象,通过console.log(this)可以查看到对象包含所有的方法和属性//2.全局变量属于this对象的属性通过console.log(this)可以查看到对象包含我们设置的全局变量我们经常在创建相同结构的Js对象会重复的设...
//我们创建每个函数默认都有一个prototype(原型)属性,这个属性是一个对象 //1.我是普通的构造方法,我的属性叫实例属性,我的方法叫实例方法 /* function Box(name,age){ this.name=name; this.age=age; this.run...