Last active
December 28, 2015 02:09
-
-
Save relaxdiego/7426320 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
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