I know there are millions Q&As out there about "this", but still this is something that even after a lot of reading and thinking I still can't fathom. Consider this example:
(quoting "Javascript Patterns" by Setfanov)
var myapp = {};
myapp.color = "green";
myapp.paint = function (node) {
node.style.color = this.color; };
var findNodes = function (callback) { // ...
if (typeof callback === "function") {
callback(found); }
// ... };
... the object "this" will refer to the GLOBAL OBJECT, because findNodes() is a global function...
But shouldn't "this" be bound to who's calling it, in this case, the findNodes() function?