Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Created October 14, 2014 17:25
Show Gist options
  • Save jordaaash/8b2d19fb49e1ddf6757b to your computer and use it in GitHub Desktop.
Save jordaaash/8b2d19fb49e1ddf6757b to your computer and use it in GitHub Desktop.
'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;
'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;
'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