12 Apr Admin
o Generally speaking, objects are “things”. For example, a piano is an object.
o Properties are terms that can describe and define a particular object. Our piano, for example, has a colour, a weight, a height, pedals, a keyboard and a lid.
o Note from the above that an object’s properties can be properties themselves. So we have the case where a piano lid is a property of the piano, but is also an object in its own right, with its own set of properties – for example, the lid has a colour, a length, and even a state of either open or closed.
o If objects are the nouns of a programming language and properties are the adjectives, then methods are the verbs. Methods are actions that can be performed on (or by) a particular object. To continue our piano example, you could play a piano, open its lid, or press the sustain pedal.
o Many programming languages have similar ways of referring to objects and their properties or methods. In general, they are hierarchical, and an object’s relationship with its properties and methods, as well as with other objects, can often be easily seen from the programming notation.
o A clear example of object hierarchy could be seen if we decided to open the lid of the piano:
o Or even more so if we wanted to press the sustain pedal of the piano:
o In these examples, document is an object, while write is a method and location is a property.
o Each method can do different things depending on what is put in the brackets (or “passed to the method as an argument”, to use the technical term). Indeed, many methods can take multiple “arguments” to modify its behaviour. Multiple arguments are separated by a comma (,).
document.write(“<h1>Hello World! </h1>”);
document.write(“<h1>;Hello World!; </h1>”);
o For this reason, it is recommended that all your statements should end with semi-colons.