var construct = function() {
var self = this;
var view = {
name: "self"
};
self.vm = {
attached: attached,
view: view
}
function attached() {
alert('view.name: ' + view.name);
view = {
name: "attached"
};
alert('view.name(after attached): ' + view.name);
alert('self.vm.view.name: ' + self.vm.view.name);
alert('this.view.name: ' + this.view.name);
}
self.vm.attached();
return self.vm;
}()
As you can see, we have a variable 'view' in a global (related to selv.vm object) context. view is passed by reference to the self.vm object.
Knowing this we can assume that 'attached' method will change the global variable and as a result self.vm.view will point to a new object.
A new local variable will be created regardeless there's the global with the same name.
A kinda unexpected behavior isn't it? Any ideas why so?