In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what are the properties and methods of JavaScript object", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "what are the properties and methods of JavaScript object" this article.
JavaScript object
Everything in JavaScript is an object: strings, numbers, arrays, dates, and so on.
In JavaScript, an object is data that has properties and methods.
Properties and methods
Property is the value associated with the object.
A method is an action that can be performed on an object.
Example
Cars are objects in real life.
The attributes of the car include name, model, weight, color and so on.
All cars have these properties, but the properties of each car are different.
The method of car can be start, drive, brake and so on.
All cars have these methods, but they are carried out at different times.
Properties of the car:
Car.name=Fiatcar.model=500car.weight=850kgcar.color=white
The method of car:
Car.start () car.drive () car.brake ()
Objects in JavaScript
In JavaScript, objects are data (variables) that have properties and methods.
When you declare a JavaScript variable like this:
Var txt = "Hello"
You have actually created a JavaScript string object. The string object has the built-in property length.
For the above string, the value of length is 5. The string object has several built-in methods at once.
Attributes:
Txt.length=5
Methods:
Txt.indexOf () txt.replace () txt.search ()
Tip: in object-oriented languages, properties and methods are often referred to as members of objects.
Create a JavaScript object
Almost all transactions in JavaScript are objects: strings, numbers, arrays, dates, functions, and so on.
You can also create your own objects.
This example creates an object named "person" and adds four attributes to it:
Person=new Object (); person.firstname= "Bill"; person.lastname= "Gates"; person.age=56; person.eyecolor= "blue"; [xss_clean] (person.firstname + "is" + person.age + "years old.")
Tip: there are many different ways to create a new js object. You can also add properties and methods to existing objects.
Access the properties of an object
The syntax for accessing object properties is: objectName.propertyName
This example uses the length property of the String object to find the length of the string:
Var message= "Hello World!"; var x=message.length
Tip: after the above code is executed, the value of x is: 12
The method of accessing the object
You can call the method with the following syntax: objectName.methodName ()
This example uses the toUpperCase () method of the String object to convert text to uppercase:
Var message= "Hello world!"; var x=message.toUpperCase ()
Tip: after the above code is executed, the value of x is: HELLO WORLD!
Do you know?
Functions that use camel-case notation are common in object-oriented languages.
You'll often see function names like someMethod () instead of some_method ().
These are all the contents of the article "what are the properties and methods of JavaScript objects?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.