[Framework] Allow prototype-style constructors

WTD-1482.
This commit is contained in:
Victor Woeltjen 2015-08-10 12:31:44 -07:00
parent a77920bd18
commit 3a0ba4f5a6
2 changed files with 10 additions and 4 deletions

View File

@ -46,7 +46,6 @@ define(
var key = extension.key,
dependencies = extension.depends || [];
if (!key) {
$log.warn([
"Cannot register ",

View File

@ -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