I'm wondering how to access the "nam"e variable with a function in a javascript object like so:
function myObj() {
this.vars = {
name: 'bob',
age: '42'
}
this.functions = {
sayName: function() {
alert(this.vars.name);
}
}
}
var obj = new myObj();
obj.functions.sayName();
What am I missing here?
I can get the name var if I pass a reference to itself like:
function myObj() {
this.vars = {
name: 'bob',
age: '42'
}
this.functions = {
sayName: function(name) {
alert(name);
}
}
}
var obj = new myObj();
obj.functions.sayName(obj.vars.name);
but that seems a little redundant... thoughts?