JavaScript Method invocation


Example

Invoking a function as a method of an object the value of this will be that object.

var obj = {
    name: "Foo",
    print: function () {
        console.log(this.name)
    }
}

We can now invoke print as a method of obj. this will be obj

obj.print();

This will thus log:

Foo