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:
car.name = Fiat
car.model = 500
car.weight = 850kg
car.color = white
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.
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.
Key-value pair is usually written as name: value (with key values separated by colons).
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:
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:
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 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.|