Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(injector) .instantiate([Type]) produced wrong result
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Feb 16, 2012
1 parent 7767392 commit eb92735
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ function createInjector(modulesToLoad) {
var Constructor = function() {},
instance, returnedValue;

Constructor.prototype = Type.prototype;
Constructor.prototype = (isArray(Type) ? Type[Type.length - 1] : Type).prototype;
instance = new Constructor();
returnedValue = invoke(Type, instance, locals);

Expand Down
9 changes: 9 additions & 0 deletions test/InjectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,15 @@ describe('injector', function() {
});


it('should instantiate object and preserve constructor property and be instanceof', function() {
var t = $injector.instantiate(['book', 'author', Type]);
expect(t.book).toEqual('moby');
expect(t.author).toEqual('melville');
expect(t.title()).toEqual('melville: moby');
expect(t instanceof Type).toBe(true);
});


it('should allow constructor to return different object', function() {
var obj = {};
var Class = function() {
Expand Down

0 comments on commit eb92735

Please sign in to comment.