Javascript: 'this' changes when assigning a property?
- by Pickels
I know 'this' can be a problem when you don't understand Javascript well but this one got me a little puzzled.
var ControlTypes = {
TextBox: function () {
console.log(this);
this.Name = "TextBox";
console.log(this);
}
}
ControlTypes.TextBox();
Firebug gives the following result:
Object {}
Object { Name="TextBox"}
The first object is ControlTypes and the second one is Textbox. Could anybody explain the behavior behind this?