As you know, __proto__
is deprecated.
MDN: Warning: The
__proto__
property is deprecated and should not be used.
what is fast and cross browser alternative for __proto__
?
In my case I change __proto__
of a function. So I can't find any alternative.
deprecated code
// one time
var proto = {};
proto.bar = function (x) { return this(x) + 10; };
proto.buzz = function () { return this(4); };
// and 100 more function proto.*
proto = _.extend(proto, (function(){}).__proto__); // underscore extend function
// update: change arguments order
// many time
var foo = function (x) { return 2 * x; }
foo.__proto__ = proto;
slow alternative (jsperf)
// many time
var foo = function (x) { return 2 * x; };
foo.bar = function (x) { return this(x) + 10; };
foo.buzz = function () { return this(4); };
// and 100 more function foo.*
Is there any fast and cross browser alternative?
As it says in the linked MDN article,
Object.getPrototypeOf()
is the new function. It seems to have pretty good browser support. For those that don't support it (except IE), you can shim it with__proto__
. ;)