From 3a0ba4f5a67a712adc9cdf1266bd043a62120d86 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 10 Aug 2015 12:31:44 -0700 Subject: [PATCH] [Framework] Allow prototype-style constructors WTD-1482. --- platform/framework/src/register/CustomRegistrars.js | 1 - platform/framework/src/resolve/ExtensionResolver.js | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/platform/framework/src/register/CustomRegistrars.js b/platform/framework/src/register/CustomRegistrars.js index 392a8c98c7..c9d40dd0ab 100644 --- a/platform/framework/src/register/CustomRegistrars.js +++ b/platform/framework/src/register/CustomRegistrars.js @@ -46,7 +46,6 @@ define( var key = extension.key, dependencies = extension.depends || []; - if (!key) { $log.warn([ "Cannot register ", diff --git a/platform/framework/src/resolve/ExtensionResolver.js b/platform/framework/src/resolve/ExtensionResolver.js index 86eb657f35..126b9ab3f9 100644 --- a/platform/framework/src/resolve/ExtensionResolver.js +++ b/platform/framework/src/resolve/ExtensionResolver.js @@ -44,13 +44,20 @@ define( implPromise = loader.load(implPath), definition = extension.getDefinition(); + // Wrap a constructor function (to avoid modifying the original) + function constructorFor(impl) { + function Constructor() { + return impl.apply(this, arguments); + } + Constructor.prototype = impl.prototype; + return Constructor; + } + // Attach values from the object definition to the // loaded implementation. function attachDefinition(impl) { var result = (typeof impl === 'function') ? - function () { - return impl.apply({}, arguments); - } : + constructorFor(impl) : Object.create(impl); // Copy over static properties