Skip to content

Commit

Permalink
Enable simple class extensions without any constructor.
Browse files Browse the repository at this point in the history
`videojs.extends` now properly handles the case when there is no
constructor provided for the child class.

Fixes #2303.
  • Loading branch information
pavelhoral committed Jul 6, 2015
1 parent 8d33388 commit a9964d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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');
});

0 comments on commit a9964d0

Please sign in to comment.