In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how Javascript creates Object objects and adds attributes. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Object-oriented (Object-oriented,OO) languages have a sign that they all have the concept of a class, through which any number of objects with the same properties and methods can be created. As mentioned earlier, there is no concept of classes in EcMAScript, so its objects are different from those in class-based languages.
ECMA defines an object as "a collection of unordered attributes whose properties can contain basic values, objects, or functions." Strictly speaking, this is equivalent to saying that an object is a set of values that do not have a specific order. Every property or method of an object has a name, and each name
Are mapped to a value. For this (and other reasons to be discussed), we can think of the object of ECMAScr'ipt as a hash table: nothing more than a set of name-value pairs, where values can be data or functions.
Each object is created based on a reference type that can be either a native type discussed in Chapter 5 or a developer-defined type.
The easiest way to create a custom object is to create an instance of 0bject, and then add properties and methods to it, as shown below:
Var person=new 0bject: ()
Person.name= "Baiheng":
Person.age=29
Person.job= "Web software"
Pezson.sayName = function () {
Alert (this.name)
}
Person.sayName ()
The above example creates an object named person and adds three properties (name, age, and job) and a method (sayName ()) to it. Where the sayName () method is used to display the value of this.name (which will be parsed to: pex-son.name). Early .JavaScljpt developers often used this pattern to create new objects. But this approach has an obvious drawback: creating many objects using the same interface results in a lot of duplicate code. To solve this problem, people began to use a variant of the factory pattern.
These are all the contents of the article "how Javascript creates Object objects and adds properties". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.