Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>var child = new this.childItemType.call(args);</p> </blockquote> <p>No, this indeed tries to use <code>Function.prototype.call</code> as a constructor (as the exception message tells you). However, there is no reason to use <code>call</code> at all:</p> <pre><code>var child = new this.childItemType(arg, arg2, …); </code></pre> <blockquote> <p>First is that I think some sort of 'this' needs to be passed to the call function, and I don't see what it'd be there.</p> </blockquote> <p>Yes, <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/call" rel="nofollow noreferrer"><code>call</code></a> expects something to be used as the <code>thisArg</code> for the function. Yet, you seem to want <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/apply" rel="nofollow noreferrer"><code>apply</code></a> as you have an <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments" rel="nofollow noreferrer">argumens array</a> <code>args</code>.</p> <p>So on what does the constructor get applied on? It's the new instance - just as like the <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/new" rel="nofollow noreferrer"><code>new</code> operator</a> does it. So to mimick it, we would use</p> <pre><code>var child = Object.create(this.childItemType.prototype); this.childItemType.apply(child, args); </code></pre> <p>For solutions that work without <code>Object.create</code> and also check the return type of the constructor, see <a href="https://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible">Use of .apply() with &#39;new&#39; operator. Is this possible?</a>.</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