mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 14:18:16 +00:00
[Framework] Allow prototype-style constructors
WTD-1482.
This commit is contained in:
@ -46,7 +46,6 @@ define(
|
|||||||
var key = extension.key,
|
var key = extension.key,
|
||||||
dependencies = extension.depends || [];
|
dependencies = extension.depends || [];
|
||||||
|
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
$log.warn([
|
$log.warn([
|
||||||
"Cannot register ",
|
"Cannot register ",
|
||||||
|
@ -44,13 +44,20 @@ define(
|
|||||||
implPromise = loader.load(implPath),
|
implPromise = loader.load(implPath),
|
||||||
definition = extension.getDefinition();
|
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
|
// Attach values from the object definition to the
|
||||||
// loaded implementation.
|
// loaded implementation.
|
||||||
function attachDefinition(impl) {
|
function attachDefinition(impl) {
|
||||||
var result = (typeof impl === 'function') ?
|
var result = (typeof impl === 'function') ?
|
||||||
function () {
|
constructorFor(impl) :
|
||||||
return impl.apply({}, arguments);
|
|
||||||
} :
|
|
||||||
Object.create(impl);
|
Object.create(impl);
|
||||||
|
|
||||||
// Copy over static properties
|
// Copy over static properties
|
||||||
|
Reference in New Issue
Block a user