The objects are described by properties and their behavior is defined by methods. An object is collection of these properties and methods which can be defined and altered and retrieved by the user.
Since all Property and method names are strings, it can be said that objects map strings to values. The string-to-value maps can be called by various names like "hash" , "hashtable" , "dictionary", "associative array" .
|drone.name = "Reaper";
drone.length = "36 ft";
drone.weight = "2225 kg";
drone.payload = "1700 kg";
The properties of drone(object) describing it are, name , length , weight and payload .
The Actions drone can perform are defined by methods takeOff() , lockTarget() , fire() and returnBase() .
In Javscript, a custom objects can be created simply by creating a new instance of the Object and then add properties and methods to it.
The following example creates an object and then assigns properties and methods to it.
The more common way of creating objects is by using object literal notation. Its a comma seperated list of colon separated name:value pairs enclosed within curly braces
The attributes of the objects are defined by their properties , these properties describe the object.
To define a property, the object name is followed by the name of the property. The properties can be accessed only via their objects.
The purpose of method is to perform some operation on the object.Eg the method calc can be used to calculate the distance travelled by a Car.