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

Enable simple class extensions without any constructor #2308

Closed
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
6 changes: 4 additions & 2 deletions src/js/extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ const extendsFn = function(superClass, subClassMethods={}) {
};
let methods = {};

if (subClassMethods.constructor !== Object.prototype.constructor) {
subClass = subClassMethods.constructor;
if (typeof subClassMethods === 'object') {
if (subClassMethods.constructor !== Object.prototype.constructor) {
subClass = subClassMethods.constructor;
}
methods = subClassMethods;
} else if (typeof subClassMethods === 'function') {
subClass = subClassMethods;
Expand Down
16 changes: 16 additions & 0 deletions test/unit/extends.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import extendsFn from '../../src/js/extends.js';

q.module('extends.js');

test('should add implicit parent constructor call', function(){
var superCalled = false;
var Parent = function() {
superCalled = true;
};
var Child = extendsFn(Parent, {
foo: 'bar'
});
var child = new Child();
ok(superCalled, 'super constructor called');
ok(child.foo, 'child properties set');
});