You invoke an object method using the following syntax:
| objectName.methodName() |
If you call the fullName property with (), it will execute like a function.
Example
| name = person.fullName; |
Adding a new method to an object is straightforward.
Example
| person.name = function () { return this.firstName + ” “ + this.lastName; }; |
In this example, JavaScript’s toUpperCase() method is used to convert text to uppercase.
Example
| person.name = function () { return (this.firstName + ” “ + this.lastName).toUpperCase(); }; |