JavaScript Object
JavaScript object data have attributes and methods.
Real-life objects, properties, and methods
In real life, a car is an object.
Object has its attributes, such as weight and color, start stop, etc. methods:
Objects | Attributes | method |
---|---|---|
car.name = Fiat car.model = 500 car.weight = 850kg car.color = white | car.start () car.drive () car.brake () car.stop () |
All cars have these properties, but the properties of each car is different.
All cars have these methods, but the time they are executed are different.
JavaScript Object
In JavaScript, almost all things are objects.
In JavaScript, objects are very important when you understand the object, you can learn JavaScript. |
You have learned assignment JavaScript variables.
The following code for the variable car set the value "Fiat":
The object is a variable, but the object can contain multiple values (multiple variables).
In the above example, the three values ( "Fiat", 500, "white") to the variable car.
In the above example, the three variables (type, model, color) to the variable car.
JavaScript object is a container of variables. |
Object definition
You can use a character to define and create a JavaScript object:
Custom JavaScript objects can span multiple lines, spaces with newline is not required:
Object Properties
You can say "JavaScript object is a container of variables."
However, we usually think "JavaScript object is the key to the container."
Key-value pair is usually written as name: value (with key values separated by colons).
Key-value pairs in JavaScript objects are usually referred to as object properties.
JavaScript object is a container attribute variables. |
Object key to the wording similar to:
- Associative arrays in PHP
- Python in dictionary
- C language hash table
- Java hash map
- Ruby and Perl hash table
Access object properties
You can access object properties in two ways:
Object Methods
The method defines a function object, and stored as an attribute of the object.
Object method by adding () call (as a function).
The examples of the person accessing the object fullName () method:
If you want to access the object person fullName property, which is defined as a string returned by the function:
JavaScript object is a container properties and methods. |
In the following tutorial you will learn more about the functions, properties, and methods of knowledge.
Object Access Method
You can use the following syntax to create object methods:
You can use the following syntax to access the object methods:
Typically fullName () method as a person object, fullName as an attribute.
There are several ways to create, use, and modify the JavaScript objects.
There are also a variety of ways to create, use, and modify the properties and methods.
In the following tutorial, you will learn more about the object of knowledge. |