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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -