Method invocation

Download javascript eBook

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

Stats

Contributors: 1
2016-07-22
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook