From f9316fcda039e4d30940162123473a09b450daeb Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Fri, 10 Jul 2015 11:42:29 -0700 Subject: [PATCH] @pavelhoral fixed subclassing without a constructor. closes #2308 --- CHANGELOG.md | 1 + src/js/extends.js | 6 ++++-- test/unit/extends.test.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/unit/extends.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 976383b76..6fd075848 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ CHANGELOG * @mischizzle fixed event.relatedTarget in Firefox ([view](https://github.com/videojs/video.js/pull/2025)) * @mboles updated JSDoc comments everywhere to prepare for new docs ([view](https://github.com/videojs/video.js/pull/2270)) * @mmcc added a currentTime tooltip to the progress handle ([view](https://github.com/videojs/video.js/pull/2255)) +* @pavelhoral fixed subclassing without a constructor ([view](https://github.com/videojs/video.js/pull/2308)) -------------------- diff --git a/src/js/extends.js b/src/js/extends.js index 1046b5d98..d9fce89d6 100644 --- a/src/js/extends.js +++ b/src/js/extends.js @@ -48,8 +48,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; diff --git a/test/unit/extends.test.js b/test/unit/extends.test.js new file mode 100644 index 000000000..a66f13292 --- /dev/null +++ b/test/unit/extends.test.js @@ -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'); +});