Here’s what the Little Red Book says about the initial value of an object:

var name = 'icepy'
var age = 18
var obj = {
  name: name.
  age: age.
  say: function() {
    console.log(this.name)
  }
}
Copy the code

In ES6, you can use a more abbreviated approach:

let name = 'icepy'
let age = 18
let obj = {
  name.
  age.
  say() {
    console.log(this.name)
  }
}
Copy the code

This is extremely simplified compared to ES5, and super can be called using properties defined by say(){}.

The most important part of this section is the enhancement of the prototype. The rest, such as the enhancement of the object, is to add a few methods that we are already familiar with:

  1. Object.is
  2. Object.assign
  3. Object.setPrototypeOf

Class A is A parent of class B, class A defines say, class B defines say, class B defines say, class B defines say, class B defines say, class B instantiates class B, call parentSay directly, at this time we will be very awkward. The say method defined by class A may not be called. In ES5, getPrototypeOf method is provided for us to obtain the prototype of any Object. According to the JS inheritance mechanism, we can know that if we call Object.getPrototypeof (this) exactly can obtain the prototype of the parent class, and then call say method is ok.

However, there is also A very embarrassing problem, so ES6 provides us with super to represent the parent class. At this time, we directly use super.say() to call the say method of class A and the say method of class B.

Interestingly, ES6 also provides a method for setting stereotypes called “setPrototypeOf”, which can set prototype objects.

If you’ve ever used the extend method similar to jQuery, you’ll be familiar with the Assign method, which is of the same type as extend and allows you to assign an attribute or method from one object to another. In the case of IS, it is a correct Boolean alignment, and most of the time behaves like ===.

For more exciting content, please follow my wechat official account: search Fed-Talk