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

Commit eb92735

Browse files
committed
fix(injector) .instantiate([Type]) produced wrong result
1 parent 7767392 commit eb92735

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ function createInjector(modulesToLoad) {
433433
var Constructor = function() {},
434434
instance, returnedValue;
435435

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

test/InjectorSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ describe('injector', function() {
605605
});
606606

607607

608+
it('should instantiate object and preserve constructor property and be instanceof', function() {
609+
var t = $injector.instantiate(['book', 'author', Type]);
610+
expect(t.book).toEqual('moby');
611+
expect(t.author).toEqual('melville');
612+
expect(t.title()).toEqual('melville: moby');
613+
expect(t instanceof Type).toBe(true);
614+
});
615+
616+
608617
it('should allow constructor to return different object', function() {
609618
var obj = {};
610619
var Class = function() {

0 commit comments

Comments
 (0)