In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how JavaScript creates objects and adds methods and properties for objects". In daily operations, I believe that many people have doubts about how JavaScript creates objects and adds methods and properties for objects. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "how JavaScript creates objects and adds methods and properties for objects". Next, please follow the editor to study!
Create an object, add methods, properties, and dynamically add and delete objects. The sample code is as follows:
Use objects to create objects directly
{
Var circle = {XRL 0THI YRU 0MIT RISUSIRUR 2}
[xss_clean] ("Center at:", circle.x, ", circle.y," Radius: ", circle.radius)
[xss_clean] ("function creates an object")
Function student (name,chinese,math,english)
{
This.name=name
This.chinese = chinese
This.math = math
This.english = english
This.avg2=avg2
}
/ /
Function avg ()
{
Return ((this.chinese + this.math + this.english) / 3)
}
Function avg2 ()
{
Return ((this.chinese + this.math + this.english) / 3) + 5)
}
}
{
Var st1 = new student ("zzc", 88pm 95jue 20)
[xss_clean] ("name" + st1.name + "")
[xss_clean] (Chinese + st1.chinese + "")
[xss_clean] ("Mathematics" + st1.math + "")
[xss_clean] ("English" + st1.english + "")
St1.avg = avg
Var avgscore = st1.avg ()
Var avgscores = st1.avg2 ()
[xss_clean] ("average score" + avgscore + "")
[xss_clean] ("average score + 5 =" + avgscores + "")
[xss_clean] ("Delete object")
[xss_clean] ("st1 object properties and methods:")
For (var i in st1)
[xss_clean] (ST1 [I] + "")
[xss_clean] ("Delete object's property (english) method (avg2)")
Delete st1.avg2
Delete st1.english
For (var i in st1)
[xss_clean] (ST1 [I] + "")
}
At this point, the study on "how JavaScript creates objects and adds methods and properties to objects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.