Differently from the other language, in JavaScript this
always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of.
What is the advantage/purpose of this behaviour compered with other languages?
Taken from http://unschooled.org/2012/03/understanding-javascript-this/
Also look into this as well.
http://javascriptplayground.com/blog/2012/04/javascript-variable-scope-this
Since you are allowed to set 'this', you can set the scope of any function you call, allowing you to do some interesting things with function closures. This is how most JS frameworks allow you to do more naturally object-oriented class behavior. This is especially helpful when you have event listeners and want to set the scope of the listening function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With