顶部信息栏,显示网站标题、Logo等资

Invoking a Function as a Method

9/5/2014 Source:Backyard [comment]


In JavaScript you can define function as object methods.

The following example creates an object (myObject), with two properties (firstName and lastName), and a method (fullName):


Example

var myObject = {
    firstName:"John",
    lastName: "Doe",
    fullName: function () {
        return this.firstName + " " + this.lastName;
    }
}
myObject.fullName();      


   The fullName method is a function. The function belongs to the object. myObject is the owner of the function.