//字面量的形式创建原型对象
/*
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>无标题文档</title> <script type...
通过FormData对象可以组装一组用 XMLHttpRequest发送请求的键/值对。它可以更灵活方便的发送表单数据,因为可以独立于表单使用。如果你把表单的编码类型设置为multipart/form-data ,则通过FormData传输的数据格式和表单通过submit() 方法传输的数据格式相同...
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>点击复制</title> </head>...
ES5中编写函数,为了给参数默认值,必须在函数体内对参数判断,着实揪心。ES6好多了。<script type="text/javascript"> function run(width = 100, height&...
在es5的时候变量只能通过+号拼接,es6种允许将变量放在大括号之中。有点类似php和c#对字符串的操作。 <script type="text/javascript"> &n...
和腾讯合作的项目活动中腾讯要求我们必须隐藏朋友圈分享功能,一直以为没有官方Api,百般查找才在文档中找到,可能是自己不太细心。微信官方文档在jsjdk的"界面操作"中有详细说明:关闭当前网页窗口接口wx.closeWindow();批量隐藏功能按钮接口wx.hideMenuIte...