Use of arrays and objects

Arrays and objects Applications

--- "the let of arr1 = [5,4,3,2];         // define an array of arr1 [2] 
---" arr2 is the let = [0,1, [2,3],. 4];                // two array, a nested array arr2 is [2] [. 1] 
--- "the let ARR3 = [4,3-, {" name ":" Lucas "},. 1]     // array object ARR3 [2] .name 
---" = arr4 the let [4,3-, { "name": [3,2,1]},. 1]     // multi-level nested arr4 [2] .name [. 1] 
--- "the let arr5 = [5,4- , function () { return the console.log ( 'Hello')}, 2,1]     // array method (function) arr5 [2] () // must exist bracket

 
--- "let obj1 = {" name ": "Lucas", "Age": 23 is};     // definition object obj1.name 
--- "the let obj2 = {" name ": {" Age ":    23}};    //Two objects, nested objects obj2.name.age 
--- "the let obj = {name:" zhangsan ", Colors: [" Red "," Green "," Blue "]};    // object array obj.colors [. 1]     
--- "OBJ4 the let = {" name ": [5,4,3, {Age: 22 is},. 1]}     // multi-level nested obj4.name [. 3] .age 
---" the let = {obj5 "name": "Lucas", My: function () {the console.log ( return  the this .name)}}   // object functions obj5.my () // if you need to add multi-level nested function obj5.my () ()
 
. 1 . conventional objects 
the let obj5 = { "name": "Lucas", My: function () {
     return  function () {Alert ( "code" )};
}}
alert(obj5.my()())    //code

2 . Common Object method 
the let obj5 = { "name": "Lucas", My: function () {
     var name = "code"         // never this point 
    return  function () {the console.log ( the this .name)}    // no point higher     
}} 
obj5.my () ()     // blank or undefine
 
3. arrow functions (. 1 ) 
the let obj = {name, Age, myfun: () => the console.log ( the this .name)}    / / arrows pointing function window, or global variable name

 Arrow function will capture their value in this context, as its value this

4. Function arrow (2 ) 
the let obj5 = { "name": "Lucas", My: function () {
     var name = "code";         // never point to the 
    return () => {Alert ( the this .name )};         // arrow pointing function higher function 
}} 
obj5.my () ()     // Lucas 
4. arrow function (3)

  var obj = {
  a: 10,
  b: function(n){
  var f = (v) => v + this.a;  1+10
  return f(n);
  },
  c: function(n) {
  var f = (v) => v + this.a;

  //var f = function(v){return v + this.a}; //输出25

  m A = {var: 20 is};
  return f.call (m, n-);  // When a function call by call () or apply () method, but only passed in the parameter, and this has no effect on
  }
}

 
 

the console.log (obj.b (. 1)); //. 11
the console.log (obj.c (. 1)); // //f.call(m,n. 11); if n = 5, the output 15

 

 

Guess you like

Origin www.cnblogs.com/jing-tian/p/11204387.html