I wrote a contrived script that illustrates what I don't understand:
var newObject = {}
newObject.testAttribute = "I'm newObject";
newObject.someMethod = function(){
console.log(this.testAttribute);
var sub_function = function(){
console.log(this.testAttribute);
}
sub_function();
}
newObject.someMethod();
In the sub_function, I expected "this" to refer to the object newObject because of closure, but the output on the console is
"I'm newObject"
undefined