2011/3/23 pnbv <p.bacelar.vasconce...@gmail.com>: > Considering a single instance object: > app = { > foo: 'afoo', > bar: 'abar', > > callbackLib: { > replyFoo: function () { > console.log(this.foo); > }, > replyBar: function () { > console.log(app.bar); > } > }, > > doSomeThing: function (){ > this.callbackLib.replyFoo.call(this); > this.callbackLib.replyBar(); > } > } > > app.doSomeThing(); > > What would be the preferred way of doing this (if there really is a > need for nested objects:)? > Thanks, > pedro If you just want to get rid of the reference to this, you could do:
app = { foo: 'afoo', bar: 'abar', callbackLib: { replyFoo: function () { console.log(app.foo); }, replyBar: function () { console.log(app.bar); } }, doSomeThing: function (){ app.callbackLib.replyFoo(); app.callbackLib.replyBar(); } } app.doSomeThing(); Although this would trigger errors in the following case: bar = app; app = {}; bar.doSomeThing(); As app is now no more. -- Poetro -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com