How to instantiate using the new operator in javascript
This article is about how to instantiate new operators in javascript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Description
1. Instantiating Person with the new operator is equivalent to calling the constructor using new.
2. New and classes are used in the interpreter, and you need to instantiate them using the constructor function.
3. The parameters passed in when the class is instantiated are used as the parameters of the constructor.
If not, the parentheses after the class name are also optional.
Example
Class Person {constructor (override) {this.foo = 'foo';if (override) {return {bar:'bar'} let p1 = new Person (), p2 = new Person (true); console.log (p1); / Person {foo: "foo"} console.log (p1 instanceof Person); / / true console.log (p2); / {bar: "bar"} console.log (p2 instanceof Person); / / false thank you for reading! This is the end of this article on "how to instantiate new operators in javascript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!