aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2012-02-16 14:32:52 -0800
committerMisko Hevery2012-02-16 14:32:52 -0800
commiteb92735c9ea3e5ddc747b66d8e895b6187a5f9e0 (patch)
tree15df18ecf434734e10180dc3a922b19ffce0766f
parent776739299b698a965ef818eeda75d4eddd10c491 (diff)
downloadangular.js-eb92735c9ea3e5ddc747b66d8e895b6187a5f9e0.tar.bz2
fix(injector) .instantiate([Type]) produced wrong result
-rw-r--r--src/Injector.js2
-rw-r--r--test/InjectorSpec.js9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/Injector.js b/src/Injector.js
index f5e35d0f..c1b9e69c 100644
--- a/src/Injector.js
+++ b/src/Injector.js
@@ -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);
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js
index dea76a6b..df326580 100644
--- a/test/InjectorSpec.js
+++ b/test/InjectorSpec.js
@@ -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() {