-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ ES6 class inheritance improvements
- Loading branch information
Showing
2 changed files
with
72 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -527,12 +527,46 @@ const defClassMethodForProto = function defClassMethodForProto(fnc) { | |
return defClassMethod(fnc, 'this.prototype'); | ||
}; | ||
|
||
/** | ||
* Make sure the namespace is configured if it's available | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.3 | ||
* @version 0.9.3 | ||
* | ||
* @param {Function} new_constructor | ||
* @param {Function} parent_constructor | ||
* @param {string} namespace | ||
*/ | ||
const ensureNamespace = function ensureNamespace(new_constructor, parent_constructor, namespace) { | ||
|
||
if (!new_constructor) { | ||
return namespace; | ||
} | ||
|
||
if (new_constructor.namespace) { | ||
return namespace; | ||
} | ||
|
||
if (!namespace && typeof parent_constructor == 'function') { | ||
namespace = parent_constructor.namespace; | ||
} | ||
|
||
if (!namespace) { | ||
namespace = ''; | ||
} | ||
|
||
Blast.defineValue(new_constructor, 'namespace', namespace == '@' ? '' : namespace); | ||
|
||
return namespace; | ||
}; | ||
|
||
/** | ||
* Make one class inherit from the other | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.1.3 | ||
* @version 0.8.18 | ||
* @version 0.9.3 | ||
* | ||
* @param {string|Function|Array} _parent Parent class to inherit from | ||
* @param {string} _namespace Namespace to store class in | ||
|
@@ -602,18 +636,7 @@ Blast.defineStatic('Function', function inherits(_parent, _namespace, _newConstr | |
} | ||
|
||
// Set the namespace on the constructor if it's given | ||
if (!newConstructor.namespace) { | ||
|
||
if (!namespace && typeof parentConstructor == 'function') { | ||
namespace = parentConstructor.namespace; | ||
} | ||
|
||
if (!namespace) { | ||
namespace = ''; | ||
} | ||
|
||
Blast.defineValue(newConstructor, 'namespace', namespace == '@' ? '' : namespace); | ||
} | ||
namespace = ensureNamespace(newConstructor, parentConstructor, namespace); | ||
|
||
if (_do_constitutors == null) { | ||
_do_constitutors = true; | ||
|
@@ -783,8 +806,8 @@ Blast.defineStatic('Function', function inherits(_parent, _namespace, _newConstr | |
temp = Fn.create(new_constructor_name, temp); | ||
temp.staticChain = newConstructor.staticChain; | ||
temp.super = newConstructor.super; | ||
Blast.defineValue(temp, 'namespace', namespace); | ||
newConstructor = temp; | ||
ensureNamespace(newConstructor, parentConstructor, namespace); | ||
} | ||
} | ||
|
||
|
@@ -814,9 +837,18 @@ Blast.defineStatic('Function', function inherits(_parent, _namespace, _newConstr | |
replacement_class = class extends parentConstructor {}; | ||
} | ||
|
||
// Make sure all static properties become "uninherited" | ||
replacement_class.children = null; | ||
replacement_class.staticChain = null; | ||
replacement_class.super = null; | ||
replacement_class.namespace = null; | ||
replacement_class.postInheritors = null; | ||
replacement_class.constitutors = null; | ||
|
||
Object.defineProperty(replacement_class, 'name', {value: new_constructor_name}); | ||
fallback_constructor = newConstructor; | ||
newConstructor = replacement_class; | ||
ensureNamespace(newConstructor, parentConstructor, namespace); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters