createObject.js 612 B

123456789101112131415161718
  1. var mixIn = require('../object/mixIn');
  2. /**
  3. * Create Object using prototypal inheritance and setting custom properties.
  4. * - Mix between Douglas Crockford Prototypal Inheritance <http://javascript.crockford.com/prototypal.html> and the EcmaScript 5 `Object.create()` method.
  5. * @param {object} parent Parent Object.
  6. * @param {object} [props] Object properties.
  7. * @return {object} Created object.
  8. */
  9. function createObject(parent, props){
  10. function F(){}
  11. F.prototype = parent;
  12. return mixIn(new F(), props);
  13. }
  14. module.exports = createObject;