I'm trying to assign a prototype inside a namespace using the following, (everything is wrapped in a global object):
prototypeObjects: {
Person : function(config){
var that = this;
this.name = config.name;
this.age = config.age;
console.log(that);
that.prototype.working = function(){
console.log(this.name + 'is working');
};
},
},
I'm then using this in the console to check it:
var me = new global.prototypeObjects.Person({name:'Mike', age:'40'});
which gives this error:
TypeError: Cannot set property 'working' of undefined
However, if I am explicit in assigning the prototype, i.e.:
prototypeObjects: {
Person : function(config){
var that = this;
this.name = config.name;
this.age = config.age;
console.log(that);
**global.prototypeObjects.Person**.prototype.working = function(){
console.log(this.name + 'is working');
};
}
},
Then it works as expected and i get the following:
global.prototypeObjects.Person {name: "Mike", age: "40", working: function}
and me.working() logs out 'Mike is working'
Can somebody explain why I can't use 'this' in this instance?