javascript - Implement the Function.prototype.apply function? -
i not care context , not want use function(). function should take function , array of parameters. example
apply(fn, args) => fn(args[0], args[1], ..., args[args.length-1]);
is possible?
var apply = function(fn, args) { var _fn = fn; args.foreach(function(arg) { _fn = _fn.bind(null, arg); }); return _fn(); }; apply( function() { console.log(arguments); }, [ 'arg 1', 'arg 2', 'arg 3', 'arg 4' ] );
Comments
Post a Comment