ES5语法的加强和总结

严格模式

'use srtict'

JSON对象

Object 扩展

  1. Object.create(prototype,[descriptors])
    作用:以指定对象为原型创建新的对象
    为新的对象指定新的属性,并对属性进行描述

    • value:指定值
    • writable:标识当前属性值是否可以修改 默认false
    • configurable 标识当前属性是否可以被删除 默认false
    • enumerable 标识当前属性是否可以枚举(for in)默认false
  2. Object.defineProperties(object,descriptors)
    作用: 为指定对象定义扩展多个属性
    get:获取当前对象回调
    set: 修改当前属性触发的回调函数,实参为修改后的值
    存储器属性 :setter getter

数组

Array.prototype.indexOf(value) 得到值在数组中的第一个下标
Array.prototype.lastindexOf(value) 得到值在数组中的最后一个下标
Array.prototype.forEach(function(item,index){})
Array.prototype.map(function(item,index){}) 遍历返回新的数组,操作后的值
Array.prototype.filter(function(item,index){}) 过滤出子数组

函数function

call()/apply()立即调用
bind() 函数返回

传参得形式

var obj = {
	username:"liujiang"
}
function test(data){
	console.log(this,data)
}

test.call (obj,33) 直接从第二个参数开始,依次传入
test.apply(obj,[99])第二个参数必须是数组
bind : 绑定this不会调用,而是将函数返回 传参跟call一样

例如:
test.bind(obj,66)();
setTimeout(function(){
console.log(this)
}.bind(obj),1000)

猜你喜欢

转载自blog.csdn.net/liujiango/article/details/107158024
ES5