Skip to content

Commit

Permalink
fix(extend): super_ should be available for backwards compatibility (#…
Browse files Browse the repository at this point in the history
…6329)

Fixes #6328
  • Loading branch information
gkatsev authored Nov 22, 2019
1 parent 1545804 commit 25d15d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/js/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const extend = function(superClass, subClassMethods = {}) {

_inherits(subClass, superClass);

// this is needed for backward-compatibility and node compatibility.
if (superClass) {
subClass.super_ = superClass;
}

// Extend subObj's prototype with functions and other properties from props
for (const name in methods) {
if (methods.hasOwnProperty(name)) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ QUnit.test('should add implicit parent constructor call', function(assert) {
assert.ok(superCalled, 'super constructor called');
assert.ok(child.foo, 'child properties set');
});

QUnit.test('should have a super_ pointer', function(assert) {
const Parent = function() {};
const Child = extend(Parent, {
foo: 'bar'
});

const child = new Child();

assert.ok(child.foo, 'child properties set');
assert.equal(child.constructor.super_, Parent, 'super_ is present and equal to the super class');
});

0 comments on commit 25d15d4

Please sign in to comment.