javascript - Nested objects referring to each other? -
suppose have this:
network = { post: function(t) { console.log(t); } protocol: { init: function() { /* network.post("init") */ } } } the commented part, how allow network.protocol.init function call network.post through sort of relative link? how can network.protocol find networks variables?
thanks. :)
this limitation of object literal syntax; can't it.
your best option reference network via property on protocol object, , add after declaring object via object literal syntax;
network = { post: function(t) { console.log(t); } protocol: { init: function() { this.network.post("init") } } } network.protocol.network = network; ... works because existance of network property deferred until execution of init itself.
Comments
Post a Comment