In an object, other than purely aesthetic reasons, I wonder if there is a way to allow access to 'this' members from within sub-objects.
Take this example (which I reflected in 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 correctly return "User B", but due to the scope, user.get () cannot access the base member.
In the context, this object will have many other members and methods that are consistent with it, so the camel camera seems so dirty; the ability to separate them into groups (user.get (), queue.foo (), room.data ()) seems more appropriate in theory. Is it practical? Is there a way to do what I ask in the way I do it, or am I just better off with camelCase?
Thanks for your thoughts!
source share