ES6 object + class

Object

Properties and methods, literal + new Object, operation property point syntax or brackets, object conversion valueOf and toString, destructuring assignment: array/parameter/object, /

Property management: add and delete: delete, detection: hasownproperty-in-, set prototype: setprototype, object merge: assign (object, merged object),

Object copy: shallow copy: reference-modify at the same time (assign, dot syntax), deep copy: create a new value (forof add related code)

Factory function: encapsulate the same operation together, do not need new, need return

Function object: function.toString() returns the function itself,

Abstract encapsulation: encapsulate the attributes let data = {name, age}

Property characteristics: get description: getownpropertydescriptor, property characteristics: configurable modification-enumeravle enumeration-writable writable-value value

class

Declaration definition: class user{}

constructor (parameter) {super(); this}

*** The methods defined in the class are in the prototype, but cannot be enumerated. The class is actually a function***

Static: class attributes, only accessible through the class name, static defines attributes and methods

Accessor: In order to prevent illegal modification of attributes, use the getset keyword to define the method, and directly call the method name when using it without parentheses

Access control: protected: external operations are not allowed, but operations can be inherited, protected: 1, _property name, prompt, modify use setter, 2, symbol: let smy = symbol() Use {[sym] as the property name in the object }, cannot be traversed, 3. Use weakmap: let host=weakmap(); Use {host.set(this, ``value)}, private: #

The newly added data type of symbol means unique, no need to create new, let sym = symbol (description parameter),

Inheritance: Property inheritance: In fact, User.call(this, name) is implemented in the function. Native js mainly manipulates the prototype chain. Class uses super to call properties and methods: originally when this is used, this points to the parent object of the current object. To access the properties of the child object, use super, this always points to the calling object, override: the subclass method and the parent class have the same name: override the parent class method, static inheritance: static properties and method extends can be inherited

Object detection: judge instanceof or isprototypeof

Guess you like

Origin blog.csdn.net/weixin_43124546/article/details/111141018