Home  >  Article  >  Web Front-end  >  What are the methods of creating objects in javascript

What are the methods of creating objects in javascript

王林
王林Original
2021-07-09 15:41:516604browse

There are three ways to create objects in JavaScript, namely using the new Object method, using the literal character {}, and using the constructor.

What are the methods of creating objects in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

We can use the new Object method to create an object using the root object Object.

What are the methods of creating objects in javascript

After creation, you can use dot notation to add properties to the object.

What are the methods of creating objects in javascript

The second method of creating an object can be created using literal characters. You can directly use the {} symbol to create an object. The properties in the object can also be created directly.

What are the methods of creating objects in javascript

#The third way to create an object is to use the constructor to create it, using the function keyword and the object name to create it.

What are the methods of creating objects in javascript

Then we use the console.log method to output and display the three objects created.

What are the methods of creating objects in javascript

In the browser console page, you can see the three object variables created.

What are the methods of creating objects in javascript

Related video tutorial sharing: js video tutorial

The above is the detailed content of What are the methods of creating objects in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn