Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extend): super_ should be available for backwards compatibility #6329

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});