Code coverage report for src/marionette.createObject.js

Statements: 54.55% (6 / 11)      Branches: 50% (1 / 2)      Functions: 33.33% (1 / 3)      Lines: 54.55% (6 / 11)     

All files » src/ » marionette.createObject.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49          1 1       1       1     1                                                         1    
// 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
  Eif (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;
})();