ES6-05: Use the constructor to create objects

Basic example

Four things that happen when new is executed

  1. Create a new empty object in memory.
  2. Let this point to this new object.
  3. Execute the code in the constructor to add properties and methods to this new object.
  4. Return this new object.

Static and instance members

  1. What is a member?
    Answer: The properties and methods in the constructor are called members.
  2. What is an instance member?
    Answer: Instance members are members added by this inside the constructor. Instance members can only be accessed through the instantiated object.
  3. What is a static member?
    Answer: The members added on the constructor itself. Static members can only be accessed through the constructor.

Add static members to the constructor and call

Guess you like

Origin blog.csdn.net/sinat_41696687/article/details/113845229