In an object, for nothing more than purely aesthetic reasons, I'm wondering if there's a way to allow access to 'this' members from within sub-objects.
Take this example (which I've mirrored at http://jsfiddle.net/Wzq7W/5/):
function BlahObj() {
this.users = {};
}
BlahObj.prototype = {
userGet: function(id) {
if (this.users[id] !== undefined) {
return this.users[id];
}
},
userAdd: function(id, name) {
if (this.users[id] === undefined) {
this.users[id] = name;
}
},
user: {
get: function(id) {
if (this.users[id] !== undefined) {
return this.users[id];
}
}
}
}
var test = new BlahObj();
test.userAdd(1, 'User A');
test.userAdd(2, 'User B');
test.userAdd(3, 'User C');
test.userGet(2);
test.user.get(1);
The userGet() method will properly return 'User B', but due to scope, user.get() cannot access the base member.
In context, this object will have many more members and methods that go along with it, so camel-casing seems so dirty; being able to separate them out by group (user.get(), queue.foo(), room.data()) seems like a better approach in theory. Is it practical? Is there a way to do what I'm asking, in the way I'm looking to do it, or would I just be better off with camelCase?
Thanks for your thoughts!