In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the method of creating objects in JavaScript". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the method of creating objects in JavaScript".
With JavaScript, you can define and create your own objects.
There are different ways to create objects:
Define and create a single object, using object text.
Define and create a single object through the keyword new.
Define an object constructor, and then create an object of the construction type.
In ECMAScript 5, you can also create objects through the function Object.create ().
Use the literals of the object:
This is the easiest way to create an object.
Using object text, you can define and create objects in a single statement.
The object literal refers to the name: value pair (such as age:62) in curly braces {}.
The following example creates a new JavaScript object with four properties:
Example
Var person = {firstName: "Bill", lastName: "Gates", age:62, eyeColor: "blue"}
Spaces and line breaks are not important. Object definitions can span multiple lines:
Example
Var person = {
FirstName: "Bill"
LastName: "Gates"
Age:62
EyeColor: "blue"
}
Use the JavaScript keyword new:
The following example also creates a new JavaScript object with four properties:
Example
Var person = new Object ()
Person.firstName = "Bill"
Person.lastName = "Gates"
Person.age = 50
Person.eyeColor = "blue"
The results of the above two examples are the same. No need to use new Object ().
For simplicity, readability, and execution speed, use the first creation method (object literal method).
Thank you for your reading, the above is the content of "the method of creating objects by JavaScript". After the study of this article, I believe you have a deeper understanding of the method of creating objects by JavaScript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.