I was looking at injector code of angular and could not understand this line
Function.prototype.bind.apply(ctor, args)
of code. Why would we call apply for bind? isn't it like calling apply for apply?
I read it on some question that it can be used to call a function of arbitrary arguments, but that can be done with arguments
object, right?
Can some one clear this?
Actual angular code:
function instantiate(Type, locals, serviceName) {
// Check if Type is annotated and use just the given function at n-1 as parameter
// e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
var ctor = (isArray(Type) ? Type[Type.length - 1] : Type);
var args = injectionArgs(Type, locals, serviceName);
// Empty object at position 0 is ignored for invocation with `new`, but required.
args.unshift(null);
return new (Function.prototype.bind.apply(ctor, args))();
}