Skip to content

Instantly share code, notes, and snippets.

@favio41
Created February 18, 2016 05:59
Show Gist options
  • Save favio41/b26fcd0c1184270f62cd to your computer and use it in GitHub Desktop.
Save favio41/b26fcd0c1184270f62cd to your computer and use it in GitHub Desktop.
var oldObj = {
first: function() {},
second: function() {}
};
var newObj = Object.create(oldObj);
newObj.third = function() {};
var myDoppelganger = Object.create(newObj);
myDoppelganger.first();
//For IE < 9
if (typeof Object.create != 'function') {
Object.create = (function() {
var Temp = function() {};
return function (prototype) {
if (arguments.length > 1) {
throw Error('Second argument not supported');
}
if (typeof prototype != 'object') {
throw TypeError('Argument must be an object');
}
Temp.prototype = prototype;
var result = new Temp();
Temp.prototype = null;
return result;
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment