Plato on Github
Report Home
createObject.js
Maintainability
75.95
Estimated # Bugs
0.07
Difficulty
12.00
SLOC/LSLOC
43 / 13
Function weight
By Complexity
By SLOC
// Mairionette.createObject // ------------------------ // A wrapper / shim for `Object.create`. Uses native `Object.create` // if available, otherwise shims it in place for Marionette to use. Marionette.createObject = (function(){ var createObject; // Define this once, and just replace the .prototype on it as needed, // to improve performance in older / less optimized JS engines function F() {} // Check for existing native / shimmed Object.create if (typeof Object.create === "function"){ // found native/shim, so use it createObject = Object.create; } else { // An implementation of the Boodman/Crockford delegation // w/ Cornford optimization, as suggested by @unscriptable // https://gist.github.com/3959151 // native/shim not found, so shim it ourself createObject = function (o) { // set the prototype of the function // so we will get `o` as the prototype // of the new object instance F.prototype = o; // create a new object that inherits from // the `o` parameter var child = new F(); // clean up just in case o is really large F.prototype = null; // send it back return child; }; } return createObject; })();