Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I properly pass arguments more than once in a javascript object literal?
    primarykey
    data
    text
    <p>I have an object literal similar to this:</p> <pre><code>var test = { myFunc1: function () { for (var i = 0, j = arguments.length; i &lt; j; i++) { alert('myFunc1: ' + arguments[i]); } }, myFunc2: function () { for (var i = 0, j = arguments.length; i &lt; j; i++) { alert('myFunc2: ' + arguments[i]); } this.myFunc1.apply(this.myFunc2, arguments); }, myFunc3: function () { for (var i = 0, j = arguments.length; i &lt; j; i++) { alert('myFunc3: ' + arguments[i]); } this.myFunc2.apply(this.myFunc3, arguments); } } </code></pre> <p>When I call "myFunc3" I want it to call "MyFunc2" with all the arguments passed to "myFunc3". This is working as expected. </p> <p>When I call "myFunc3" I want it to call "myFunc2" with all passed arguments, and I want myFunc1 to be called with all passed arguments that were originally passed to "myFunc3".</p> <pre><code>test.myFunc3('a', 'b'); </code></pre> <p>Currently when I call this, I get 4 alert boxes, 2 for myFunc3 and 2 for myFunc2. Then I get an error: </p> <pre><code>Uncaught TypeError: Cannot call method 'apply' of undefined </code></pre> <p>If I need to pass a set of arguments more than one level deep in an object how can I do this? Is there a better more correct way to do this?</p> <p>Here is a jsFiddle to demonstrate. </p> <p><a href="http://jsfiddle.net/taggedzi/fmPAQ/2/" rel="nofollow">http://jsfiddle.net/taggedzi/fmPAQ/2/</a></p> <p>Thanks in advance. Pure javascript only, no jquery please. Needs to work cross browser and platform. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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