Article Image
read

In javascript, the this object in a callback is the object from where it is called. If you have a function that is not contained by an object (recognisable by the curly braces: {}), the this object will be window. You can check this by writing a console.log(this).

So, a helper function:

When you execute obj.bar() somewhere on your console their will be an output of the window object.

To allow for access of this.name in the anonymous function, change this:

More information on this can be found at the Mozilla developer network.

One last quick tip: a good JS developer always adds mdn to his Google query to get good documentation and not the commercial w3schools docs.

Cheers!

Blog Logo

Hannes Van De Vreken


Published

Image

Hannes Van De Vreken

Working as a web developer. On his blog he writes about things he learned while experimenting with tools he might use to speed up his development.

Back to Overview