Here is what you will learn:
- the concept of object in web programming;
- what object properties are;
- what object methods are.
What is an object in Geeky talk?
Real world objects are things like books, cars, balls, etc. We humans deal with the world around us by interacting with and manipulating things, that is, objects.
- the Math object, that you used to generate random numbers and round off decimals;
- HTML elements like the button object that you used to manipulate its value attribute;
- the Date object that you used to retrieve the current date.
Properties and methods
The answer is: not much differently from the way we humans manipulate real world objects. We do this by interacting with the qualities and capabilities that belong to individual objects.
Let’s take a ball as our example. We interact with the ball by means of some of its qualities (its roundness, its hardness, its size, etc.). Also, we interact with the ball on the bais of what we expect the ball’s behavior to be like (we expect that we can launch the ball without breaking it, that we can throw it against a wall and it bounces back, etc.).
Properties are values associated with an object. For example, an HTML element object has a value property (like the button object you’re familiar with), and an innerHTML property, that you used to add new mark-up to the web page.
Methods represent what an object can do, its behavior, and are very much like functions.
How do you associate an object with a property or a method?
If you wondered what that odd-looking ( . ) dot notation in document.write() or Math.random(), and so on, meant in previous lessons, here’s the answer.
//use the random() method of the Math object Math.random(); //use the write() method of the document object document.write(); //use the length property of the string object myStringText.length;
In the next lesson you will learn about the most widely used properties and methods of the String object.