Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a name for partial function application with a fixed argument list?
    primarykey
    data
    text
    <p>I'm trying to find out if there's a concept or an existing formal name for this use of partial function application/binding.</p> <p>I've seen it in multiple places/libraries in different names but here's more or less the concepts I'm talking about vs. the normal curry/bind/partial function application:</p> <pre><code>//Typical usage of bind/curry: fn = bind(function(){console.log(this, arguments)}, context, 'arg 1', 'arg 2'); fn('arg 3'); //logs out arg 1, arg 2, and arg 3 //What I'm looking for: fn = makeFn(function(){console.log(this, arguments)}, context, 'arg 1', 'arg 2'); fn('arg 3'); //logs out arg 1, arg 2 // (Notice that arg 3 is ignored because it's not in the defined list of arguments). </code></pre> <p>An example use case for something like this:</p> <pre><code>obj = { toggle: function(force, config){ node[force || this.hidden ? 'show' : 'hide'](config &amp;&amp; config.someSetting); this.hidden = !this.hidden; }, hidden: false } node.on('click', makeFn(obj.toggle, obj, true)); </code></pre> <p>(using bind/curry pass along an event object or whatever other arguments are sent in, but the function we're defining would be trying to optionally use that as a completely different type of argument).</p> <p>I've seen this pattern called multiple things in different libraries with some slightly different syntaxes/abilities.</p> <p>Facebook's js uses Function.prototype.shield(context, [args...]), Mootools uses Function.prototype.pass(args, [context]), Sencha (née ExtJS) has Function.prototype.createDelegate(fn, args, [appendArgs = false]) and I've even seen some called partial(fn, context, args) (however partial usually has the added ability to pass around a placeholder to allow the passing of different default arguments; I'm avoiding this due to the performance overhead of looping over the argument list on every function call).</p> <p>Is this a formal concept, or is it only an implied one that requires some new name?</p> <p>Thanks in advance :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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