-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.js
More file actions
23 lines (23 loc) · 876 Bytes
/
extend.js
File metadata and controls
23 lines (23 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Implementation of class extension (constructor reuse)
(function (exports) {
'use strict';
function extend(Parent, Child, proprieties) {
// make a new constructor that calls parent's then child's consctructors.
function Constructor() {
if (Parent) { Parent.apply(this, arguments); }
if (Child) { Child.apply(this, arguments); }
}
// new prototype inherits from Parent's
var prototype = Object.create(Parent.prototype),
// copy proprieties to new prototype
keys = Object.keys(proprieties);
keys.forEach(function (key) {
prototype[key] = proprieties[key];
});
// assign prototype to constructor;
Constructor.prototype = prototype;
// return the constructor
return Constructor;
}
exports.extend = extend;
}(exports));