Created
February 18, 2016 05:59
-
-
Save favio41/b26fcd0c1184270f62cd 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
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