df4d2bc1f554332c5e79babc126f6e9e5c4bf357
[yaffs-website] / node_modules / video.js / es5 / extend.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
6
7 var _log = require('./utils/log');
8
9 var _log2 = _interopRequireDefault(_log);
10
11 var _obj = require('./utils/obj');
12
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
14
15 /**
16  * @file extend.js
17  * @module extend
18  */
19
20 /**
21  * A combination of node inherits and babel's inherits (after transpile).
22  * Both work the same but node adds `super_` to the subClass
23  * and Bable adds the superClass as __proto__. Both seem useful.
24  *
25  * @param {Object} subClass
26  *        The class to inherit to
27  *
28  * @param {Object} superClass
29  *        The class to inherit from
30  *
31  * @private
32  */
33 var _inherits = function _inherits(subClass, superClass) {
34   if (typeof superClass !== 'function' && superClass !== null) {
35     throw new TypeError('Super expression must either be null or a function, not ' + (typeof superClass === 'undefined' ? 'undefined' : _typeof(superClass)));
36   }
37
38   subClass.prototype = Object.create(superClass && superClass.prototype, {
39     constructor: {
40       value: subClass,
41       enumerable: false,
42       writable: true,
43       configurable: true
44     }
45   });
46
47   if (superClass) {
48     // node
49     subClass.super_ = superClass;
50   }
51 };
52
53 /**
54  * Function for subclassing using the same inheritance that
55  * videojs uses internally
56  *
57  * @param {Object} superClass
58  *        The class to inherit from
59  *
60  * @param {Object} [subClassMethods={}]
61  *        The class to inherit to
62  *
63  * @return {Object}
64  *         The new object with subClassMethods that inherited superClass.
65  */
66 var extendFn = function extendFn(superClass) {
67   var subClassMethods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
68
69   var subClass = function subClass() {
70     superClass.apply(this, arguments);
71   };
72
73   var methods = {};
74
75   if ((0, _obj.isObject)(subClassMethods)) {
76     if (typeof subClassMethods.init === 'function') {
77       _log2['default'].warn('Constructor logic via init() is deprecated; please use constructor() instead.');
78       subClassMethods.constructor = subClassMethods.init;
79     }
80     if (subClassMethods.constructor !== Object.prototype.constructor) {
81       subClass = subClassMethods.constructor;
82     }
83     methods = subClassMethods;
84   } else if (typeof subClassMethods === 'function') {
85     subClass = subClassMethods;
86   }
87
88   _inherits(subClass, superClass);
89
90   // Extend subObj's prototype with functions and other properties from props
91   for (var name in methods) {
92     if (methods.hasOwnProperty(name)) {
93       subClass.prototype[name] = methods[name];
94     }
95   }
96
97   return subClass;
98 };
99
100 exports['default'] = extendFn;