__proto__ is deprecated. What is a fast and cross-browser alternative?

As you know, is __proto__ outdated .

MDN: Warning. The property __proto__is deprecated and should not be used.

What is a quick and cross-browser alternative for __proto__? In my case, I am changing the __proto__functions. Therefore, I can not find an alternative.

outdated 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 a quick and cross-browser alternative?

+4
source share
2 answers

MDN, Object.getPrototypeOf() . , . , ( IE), __proto__.;)

if (!Object.getProtoTypeOf) {
    Object.getProtoTypeOf = function(obj) {
        return obj.__proto__;
    };
}
+2

__proto__ , Function.prototype

proto = _.extend(Function.prototype, proto); // underscore extend function

, .

ECMAScript 6 __proto__, Object.setPrototypeOf(), .

+2

All Articles