Let's go directly to the code:
The code above is an example of the problem and should be very self-explaining. The vars of AnotherMethod overwrite the vars of Method, which was called first. I have no idea why this happens, and I really don't want it to happen. Renaming the variables helps, but it is a very, very poor solution and does not work when recursing a function as follows:Code:<script language="JavaScript" type="text/javascript"> var MyClass = { Method : function(num) { a = num; // a = 2 someValueINeed = MyClass.AnotherMethod(10); alert(a); // now a = 10! wtf? }, AnotherMethod : function(someNum) { a = someNum; return a; } }; MyClass.Method(2); </script>
Now, if you have ANY idea how to prevent this from happening, PLEASE tell me. It'd be greatly appreciated.Code:<script language="JavaScript" type="text/javascript"> var MyClass = { Method : function(num,preventEndlessRecursion) { a = num; if (preventEndlessRecursion) { // prevent endless loop :) MyClass.Method(5); alert(a); // a = 5! again, wtf? } } }; MyClass.Method(2,true); </script>





Bookmarks