Skip to content

Instantly share code, notes, and snippets.

@zjhiphop

zjhiphop/create.js

Forked from davidaurelio/create.js
Created Aug 13, 2013
Embed
What would you like to do?
var BaseObject = {
create: function create() {
var instance = Object.create(this);
instance._construct.apply(instance, arguments);
return instance;
},
extend: function extend(properties, propertyDescriptors) {
propertyDescriptors = propertyDescriptors || {};
if(properties){
var simpleProperties = Object.getOwnPropertyNames(properties);
for (var i = 0, len = simpleProperties.length; i < len; i += 1) {
var propertyName = simpleProperties[i];
if(propertyDescriptors.hasOwnProperty(propertyName)) {
continue;
}
propertyDescriptors[propertyName] =
Object.getOwnPropertyDescriptor(properties, propertyName);
}
}
return Object.create(this, propertyDescriptors);
},
_construct: function _construct() {},
_super: function _super(definedOn, methodName, args) {
if (typeof methodName !== "string") {
args = methodName;
methodName = "_construct";
}
return Object.getPrototypeOf(definedOn)[methodName].apply(this, args);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.