From 776739299b698a965ef818eeda75d4eddd10c491 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Wed, 8 Feb 2012 16:12:11 -0800 Subject: fix($injector): instantiate returns instance, if non-object value returned from constructor --- src/Injector.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Injector.js b/src/Injector.js index 94154bec..f5e35d0f 100644 --- a/src/Injector.js +++ b/src/Injector.js @@ -429,12 +429,15 @@ function createInjector(modulesToLoad) { } } - function instantiate(Type, locals){ - var Constructor = function(){}, - instance; + function instantiate(Type, locals) { + var Constructor = function() {}, + instance, returnedValue; + Constructor.prototype = Type.prototype; instance = new Constructor(); - return invoke(Type, instance, locals) || instance; + returnedValue = invoke(Type, instance, locals); + + return isObject(returnedValue) ? returnedValue : instance; } return { -- cgit v1.2.3