Note that there are some explanatory texts on larger screens.

plurals
  1. POUse apply with a function constructor
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <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> </blockquote> <p>I have 5 or 6 variable assignments of the form</p> <pre><code>var analyteSelection = new TemplatedSelectionContainer($('.analyte-container', this), helpers, optionsTemplate); var instrumentSelection = new AssetBackedSelection($('.instrument-container', this), helpers, optionsTemplate, Assets.instruments, 'Instrument'); var methodSelection = new AssetBackedSelection($('.method-container', this), helpers, optionsTemplate, Assets.methods, 'Method'); </code></pre> <p>As you can see, a significant amount of portion of these constructors are very much alike. It would be nice if I could create a little generic currying builder that would allow me to do something like:</p> <pre><code>var newSel = selectionContainerBuilder(this, helpers, optionsTemplate) var analyteSelection = newSel(TemplatedSelectionContainer, '.analyte-container'); var instrumentSelection = newSel(AssetBackedSelection, '.instrument-container', Assets.instruments, 'Instrument'); var methodSelection = newSel(AssetBackedSelection, '.method-container', Assets.methods, 'Method'); </code></pre> <p>I can achieve something similar with</p> <pre><code>var selectionContainerBuilder = function(ctx, helpers, optionsTemplate) { return function(FuncDef, selector, a, b, c, d, e, f) { return new FuncDef($(selector, ctx), helpers, optionsTemplate, a,b,c,d,e,f); } } </code></pre> <p>But seriously ick. I would like to just be able to splice the first three known parameters to the beginning of the arguments array and apply it to the FuncDef but I'm being foiled by the need to use the new operator.</p> <p>And before someone asks, I can't do new-operator enforcement inside of FuncDef because it's being generated by the coffeescript class keyword.</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.
 

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