Skip to content

Instantly share code, notes, and snippets.

@relaxdiego
Last active December 28, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relaxdiego/7426320 to your computer and use it in GitHub Desktop.
Save relaxdiego/7426320 to your computer and use it in GitHub Desktop.
RB.Object = {
// Douglas Crockford's technique for object extension
// http://javascript.crockford.com/prototypal.html
create: function(){
function F(){}
F.prototype = arguments[0];
var obj = new F();
// Add all the other arguments as mixins that
// 'write over' any existing methods
for (var i=1; i<arguments.length; i++) {
var methods = arguments[i];
if (typeof methods == 'object'){
for(methodName in methods) obj[methodName] = methods[methodName];
}
}
return obj;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment