Created
October 14, 2014 17:25
-
-
Save jordaaash/8b2d19fb49e1ddf6757b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var slice = Array.prototype.slice, | |
copyProperty; | |
copyProperty = function () { | |
var properties = slice.call(arguments), | |
to = properties.pop(), | |
from = properties.pop(), | |
i, length, property, descriptor; | |
for (i = 0, length = properties.length; i < length; i++) { | |
property = properties[i]; | |
descriptor = Object.getOwnPropertyDescriptor(from, property); | |
Object.defineProperty(to, property, descriptor); | |
} | |
}; | |
module.exports = copyProperty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var copyProperty = require('./copy_property'), | |
extend; | |
extend = function (Child, Parent) { | |
var properties = Object.keys(Parent).concat(Parent, Child), | |
Class; | |
copyProperty.apply(null, properties); | |
Class = function () { | |
this.constructor = Child; | |
}; | |
Class.prototype = Parent.prototype; | |
Child.prototype = new Class; | |
Child._super = Parent.prototype; | |
return Child; | |
}; | |
module.exports = extend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var extend = require('./extend'), | |
subclass; | |
subclass = function (Parent, constructor) { | |
var Child; | |
if (constructor == null) { | |
Child = function () { | |
return Child._super.constructor.apply(this, arguments); | |
}; | |
} | |
else { | |
Child = function () { | |
Child._super.constructor.apply(this, arguments); | |
return constructor.apply(this, arguments); | |
}; | |
} | |
extend(Child, Parent); | |
return Child; | |
}; | |
module.exports = subclass; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment