I am pretty new in OO paradigm in JavaScript language (I came from Java) and I have the following doubt related to the correct meaning of this param in this specific case.
I have the following code:
var obj = {
fn:function(a,b) {
log(this-);
}
}
Ok, from what I have understand (correct me if I am doing wrong assertion) the previous code define an ob object that contain a fnction named fn.
First doubt: doing in this way am I creating an instance of this object (creating in memory) or am I only declaring it (as a Java class)?
I think that I am creating in memory a specific instance of this object but I am not sure of this...
Ok, then doing:
obj.fn(3,4);
here the this value is the identification of the specific obj object (the instance) on which I am calling the fn() function.
Is it my reasoning correct or am I missing something?
And what happens if I don't declare the fn() function into an object definition? What happens if I put it dirctly into a .js file? Is this keyword refred to the global object?