Javascript Object.create In Old Ie
Is there a way to make this code backwards compatible with IE6/7/8? function Foo() { ... } function Bar() { ... } Bar.prototype = Object.create(Foo.prototype); The main
Solution 1:
Pointy's comment as an answer
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create#Polyfill
if (!Object.create) {
Object.create = function (o) {
if (arguments.length > 1) {
thrownewError('Object.create implementation only accepts the first parameter.');
}
functionF() {}
F.prototype = o;
returnnewF();
};
}
This polyfill covers the main use case which is creating a new object for which the prototype has been chosen but doesn't take the second argument into account.
Post a Comment for "Javascript Object.create In Old Ie"