Skip to content

Commit

Permalink
working on #23
Browse files Browse the repository at this point in the history
  • Loading branch information
remojansen committed Oct 18, 2015
1 parent 0a878e2 commit 9c854e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dist/inversify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions source/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,9 @@ class Kernel implements IKernel {
// Number, Date, etc.) with an array of arguments
private _construct<TImplementationType>(
constr : { new(): TImplementationType ;}, args : Object[]) : TImplementationType {

function F() : void {
constr.apply(this, args);
}

F.prototype = constr.prototype;
return new F();
return new (Function.prototype.bind.apply(constr, [null].concat(args)));
}

}

export { Kernel };
30 changes: 30 additions & 0 deletions test/inversify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ var expect = chai.expect;

declare var Map;

// Polyfill for Function.prototype.bind more details at
// https://github.com/ariya/phantomjs/issues/10522
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};

if (this.prototype) {
// native functions don't have a prototype
fNOP.prototype = this.prototype;
}
fBound.prototype = new fNOP();

return fBound;
};
}

//******************************************************************************
//* MOCKS AND STUBS
//******************************************************************************
Expand Down

0 comments on commit 9c854e7

Please sign in to comment.