Porting C# to javascript is causing scoping issues -


I'm trying to implement the algorithm found in C # in JavaScript and I'm facing some problems .

Actually I have to go through context in JS. I have broken the problem for the following example code, assuming that you have the following C #:

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Name Location ConsoleApplication1 {class program {static void key (string [] args) {wordPoco [] myArray = new wordPoco [4] {new wordPoco {word = "this"}, new wordPoco {word = "is?"}, New WordPoco {word = "a"}, new word poko {word = "test"}}; Console.witline ("price before recurring"); Myrkersiv function (referee); Console.Read (); } Private Static Zero MyRecursiveFunction (Ref Word Poko [] myArray) {if (myArray.Length & lt; = 0) {Console.WriteLine (); Console.light line ("value after recurring"); Return; } WordPoco [] NewArray = (WordPo []) myArray.Clone (); Console Write ("Array Value:"); For (int j = 0; j and lt; neue langeth; j ++) {console.light (newer [j] .word + ""); } Console. Wrightite (); // js word poko [] popping array = popping new words [newArray.Length - 1]; Array.Copy (Newer, PoppedEre, Newer.length- 1); NewArray = (verbose []) poppedArray.Clone (); Myrekersiv Function (Refu Nuere); MyArray = (wordPoco []) newArray.Clone (); Console Write ("Array Value:"); For (int j = 0; j and lt; miare; langeth; j ++) {console.light (myrise [j] .wish + ""); } Console. Wrightite (); }} Public square wordPoco {public string word; }}  

This is the reason that the production output:

  before the recursion ArrayValue: it's ArrayValue :: it's an ArrayValue: this is a test ArrayValue is the value after the recursion ArrayValue: ArrayValue: ArrayValue: ArrayValue:  

should not generate the same result following JS

  $ (document) (Word: "a"}, {word: "test"}]; debugBox.append (" & Lt; p & gt; Recursion & lt value; / b & gt; & lt; br / & gt;;); MyRecursiveFunction (myArray); Function MyRecursiveFunction (myArray) {if (myArray.length & lt; = 0) {Debugbox. Enclosed ("& lt; p> Recursion & Lt value; / b>  return false;} newArray = $ .extend (true, [], myArray); debugBox.append ("ArrayValue:"); For (var j = 0; j & lt; newArray.length; j ++) debugBox.append (newer [j] .word + ""); debugBox.append ("& lt; br />") ; NewArray.pop (); arguments.callee (newArray); MyArray = $ Expansion (true, [], newer); DebugBox.append ("ArrayValu:"); For (var j = 0; j & lt; myArray.length; j ++) debugBox.append (myArray [j] .word + ""); DebugBox.append ("& lt; br / & gt;"); }});  

The results I am getting are actually:

  Value before recurring value: This is a test value: This is a value: This value is: After this recursive value, value: value: this value: this value is: this one  

Thank you very much for your time, Kevin

The easiest answer is to replace it with an invalid method that gives the array.

Then the C # declaration will change like this:

  private static wordPoco [] MyRecursiveFunction (wordPoco [] myArray)  

when You recurse what you want:

  NewArray = My exemplary work (Newer);  

And you can just return to myArray at the end of the method.

This pass-through-reference


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -