Created
March 19, 2009 21:25
-
-
Save thomaslang/82070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this one works, calling Obj1.f(1) gives [1,3,5,7,9] | |
| Obj1 = { | |
| n: 10, | |
| s: [], | |
| f: function(m){ | |
| if(m<=this.n){ | |
| this.s.push(m); | |
| this.g.g1(m+1); | |
| } | |
| }, | |
| g: function(m){ | |
| this.f(m+1) | |
| } | |
| }; | |
| // this one does not work, error: this.f is not a function source | |
| Obj2 = { | |
| n: 10, | |
| s: [], | |
| f: function(m){ | |
| if(m<=this.n){ | |
| this.s.push(m); | |
| this.g.g1(m+1); | |
| } | |
| }, | |
| g: { | |
| g1: function(m){ | |
| this.f(m+1) | |
| } | |
| } | |
| } | |
| /* | |
| These examples are made up to illustrate the problem. | |
| In the real code I don't see a way to replace this recursion. | |
| So I would like to know if there is a way to make Obj2 work. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment