JS_17 ES5,ES6

ES5

Strict Mode

  1. Definition method use strict
  2. characteristic:
    1. We must define the variables using var
    2. There is scope eval
    3. Prohibition custom function in this point window
    4. 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()
Published 62 original articles · won praise 33 · views 10000 +

Guess you like

Origin blog.csdn.net/zjbyough/article/details/95244194