ES5
Strict Mode
- Definition method
use strict
- characteristic:
- We must define the variables using var
- There is scope eval
- Prohibition custom function in this point window
- Object attributes can not have duplicate names
JSON object
- json.stringify (obj / arr): js target object into json
- json.parse (str): json object into the object js
Object expand
Object.create(prototype,[descriptors])
- Role: create a new object with the specified object as the prototype
- descriptors parameters
- value: specified value
- writeable: Can Modify
- configurable: Can Delete
- enumerable: if you can use for in traversal
var test1 = {
name : "test1",
}
var test2 = {}
test2 = Object.create(test1,{
sex:{
value : "boy",
writable : true,
configurable : true,
enumerable : true,
},
age : {
value : 18,
}
})
Arrey expand
- indexOf (): get the first index value in the array
- lastIndexOf (): acquire a value of the last index in the array
- forEach (): iterate
- map (): returns the array after processing
- filter (): Filter Array
var arr = [1,2,3,,2,3,4,5,3,4,5,67,7,8,0]
var index_of = arr.indexOf(3)
console.log(index_of) // 2
var lastindex_of = arr.lastIndexOf(3)
console.log(lastindex_of)
// 无法使用break跳出遍历
arr.forEach(function(v){
console.log(v)
})
var arr2 = arr.map(function(v){
return v + 1
})
console.log(arr2)
var arr3 = arr.filter(function(v){
return v>2
})
console.log(arr3)
Call,apply,bind
- call (): argument transmitted directly
- apply (): pass parameters in the form of an array
- bind (): direct transmission parameters, is not called immediately return function
var fun = function(a,b){
console.log(this)
console.log(a+b)
}
var fun1 = function(){
var fun1_name = "fun1"
}
fun.call(fun1,"aa","bb")
fun.apply(fun1,["aa","bb"])
// 不会立即调用
var fun3 = fun.bind(fun1,"aa","bb")
fun3()