Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've come up with another solution, though this one requires you to change some of your code. Instead of calling methods as usual:</p> <pre class="lang-js prettyprint-override"><code>myObject.myMethod1("Hello", "world"); </code></pre> <p>You'll need to switch to calling methods like this:</p> <pre class="lang-js prettyprint-override"><code>myObject.do("myMethod1", "Hello", "world"); </code></pre> <p>Here's a complete example of how it works:</p> <pre class="lang-js prettyprint-override"><code>Object.prototype.do = function stackHelper() { // Convert the arguments into an array. var argumentArray = Array.prototype.slice.call(arguments); // Remove the first argument, which is the function's name. var functionString = argumentArray.shift(); try { this[functionString].apply(this, argumentArray); } catch (e) { if (typeof e.stack === "undefined" || e.stack === null) { e.stack = $.stack; } throw e; } }; var myObject = { myMethod1: function myMethod1(myArg1, myArg2){ this.do("myMethod2", myArg1, myArg2); }, myMethod2: function myMethod2(myArg1, myArg2){ this.do("myMethod3", myArg1, myArg2); }, myMethod3: function myMethod3(myArg1, myArg2){ $.writeln(myArg1 + ", " + myArg2 + "!"); var foo = null; foo.bar; // Throws an error. }, }; try { myObject.do("myMethod1", "Hello", "world"); } catch (e) { $.writeln("Stack: " + e.stack); } </code></pre> <p>The output looks like this:</p> <pre><code>Hello, world! Stack: [do.jsx] stackHelper("myMethod1","Hello","world") myMethod1("Hello","world") stackHelper("myMethod2","Hello","world") myMethod2("Hello","world") stackHelper("myMethod3","Hello","world") </code></pre> <p>It's not a great solution, but at least it works on all errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload