JS <new and constructor>

new X()

new X() does four things automatically

  1. Create empty objects automatically
  2. The prototype is automatically associated with an empty object, and the prototype address is specified as X.prototype
  3. Automatically run the constructor with an empty object as the this keyword
  4. Automatically return this

Constructor X

definition

  • Constructor is a function that can construct an object

The X function itself is responsible for adding properties to the object itself. The
X.prototype object is responsible for saving the common properties of the object.

other

Object.__proto__ === its constructor.prototype

Each function has a prototype attribute.
Each prototype has a constructor attribute
.······The
part of speech
function behind new, using noun forms such as new Person(), new Object() and
other functions, generally use verbs at the beginning, such as createSquare (5), createElement ( 'div')
······
case
first letter capitalized all constructors (special function for creating an object)
all constructed objects, the first letter lowercase

Guess you like

Origin blog.csdn.net/JankoY/article/details/112915610