|
|
|
|
|
by sbank
4567 days ago
|
|
From the top of my head, from someone who currently seeks work as a full stack (Rails) developer: I would ask if you by "method" mean function defined on an object. If so, this refers to the method's object. If not, this can take on 5 values. In the global scope it is the global object; in a constructor it is the newly created object; in a function (not defined on an object - and also goes for functions defined within methods defined on objects) it is the global object; in a method (defined on object) it is the object, and finally it can be set explicitly with functions like call and apply. How did I do? (Serious question. I think my answer is good, but I also struggle with a serious form of imposter syndrome.) |
|
I would also add, though, that function definition is not the critical aspect to define this. The value of this primarily varies based on how the function is called, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...