Passed
Branch master (f98097)
by Eric
01:55 queued 59s
created

src/inherits.js   A

Complexity

Total Complexity 6
Complexity/F 6

Size

Lines of Code 22
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
c 1
b 0
f 1
nc 4
dl 0
loc 22
rs 10
ccs 10
cts 10
cp 1
crap 0
wmc 6
mnd 1
bc 4
fnc 1
bpm 4
cpm 6
noi 0
1
/*!
2
 * inherits.js | v0.2.0 | Easily inherit prototypes.
3
 * Copyright (c) 2017 Eric Zieger (MIT license)
4
 * https://github.com/theZieger/inherits.js/blob/master/LICENSE
5
 *
6
 * inherit the prototype of the SuperConstructor
7
 *
8
 * Warning: Changing the prototype of an object is, by the nature of how
9
 * modern JavaScript engines optimize property accesses, a very slow
10
 * operation, in every browser and JavaScript engine. So instead of using
11
 * Object.setPrototypeOf or messing with __proto__, we create a new object
12
 * with the desired prototype using Object.create().
13
 *
14
 * @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
15
 *
16
 * @param {Object} Constructor
17
 * @param {Object} SuperConstructor
18
 *
19
 * @throws {TypeError} if arguments are `null`, `undefined`, or
20
 *                     `SuperConstructor` has no prototype
21
 *
22
 * @returns {Void}
23
 */
24 1
module.exports = function(Constructor, SuperConstructor) {
25 6
  if (Constructor === undefined || Constructor === null) {
26 2
    throw new TypeError('Constructor argument is undefined or null');
27
  }
28
29 4
  if (SuperConstructor === undefined || SuperConstructor === null) {
30 2
    throw new TypeError('SuperConstructor argument is undefined or null');
31
  }
32
33 2
  if (SuperConstructor.prototype === undefined) {
34 1
    throw new TypeError('SuperConstructor.prototype is undefined');
35
  }
36
37
  /**
38
   * for convenience, `SuperConstructor` will be accessible through the
39
   * `Constructor.super_` property
40
   */
41 1
  Constructor.super_ = SuperConstructor;
42
43 1
  Constructor.prototype = Object.create(SuperConstructor.prototype);
44 1
  Constructor.prototype.constructor = Constructor;
45
};
46