In JavaScript, functions are callable.
Can I remove this attribute from a function, leaving only a normal object?
var foo = function () {};
foo.[[ca
I like providing an additional point of view to what Bergi already did mention, also encouraged by this answer within the OP's question.
For what purpose? – user3749178 Apr 16 at 16:18
.
@user3749178 Curiosity. – Ben Aston Apr 16 at 16:19
besides var obj = Object.assign(Object.create(Object.getPrototypeOf(fn)), fn);, that depends on ES6, there is an ES3 compatible approach that does wrap function objects into callable objects. Thus those objects are not callable anymore by the call operator (), but such objects do still expose two call methods call and apply.
Since this approach prevents on one hand function objects being invoked by () (methods/functions) or by the new operator (instantiation), on the other hand it still supports delegation (function based mixins/traits).
the gist hosted code of Function.toApplicator