Simplification of the object-oriented for ES6 ---

A, ES6 --- simplification object-oriented

1. Providing a single object at a simplified 2:

1.1 If the variable attributes of the object from the outside of the object, and variable names exactly and attribute names the same. Then do not write the same name twice,

Just write it again.

1.2 Method of all objects, no longer need to write ": function"

Emphasized: The method of removing the object: function, the function is not equivalent to the arrow. Prominent feature of this intact unchanged!

So, get rid of: function, simply shorthand, did not change any principles.

      var eid = 1001;
        function intrSelf(){
            console.log ( `my number is $ {this.eid}`);
        }
        var friends = [ "bright", "then ran", "stuff"];
        Eric = {
            eid, // eid: eid,
            ename: "eh Rick"
            intrSelf,// intrSelf:intrSelf
            friends,// friends:friends
            run(){ //:function(){
                console.log ( `$ {this.ename}` on the run);
            }
        }
        console.log(eric);
        eric.intrSelf();
        eric.run();
 
二、class
      What is: all objects in a unified structure properties and methods defined program structure focused on one type of
      Why: Each Type: Array Student Date has two parts: the prototype object constructor +
       Constructors: responsible for defining the properties of all child objects unified structure, and is responsible for creating child objects.
       Prototype object: responsible for the preservation of all property values ​​and methods of child objects have in common.
However, in ES5, the constructor and prototype objects are defined separately.
 

Guess you like

Origin www.cnblogs.com/sna-ling/p/11878112.html