Apparently using __proto__
property is still the main way of manipulating prototype chains, even though this is not standards compliant and IE does not support it. Though you can also construct inheritance through the use of new
constructor this seems like an unnecessary complication compared to __proto__
property or standards compliant Object.getPrototypeOf
function.
Edit:
As stated in the answers, this method does exist now (ES6 standard). Be aware of the performance warning, though: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
It is part of the ES6 harmony draft:
I am using it now in the latest release of Chrome.
var proto = {
foo: 'bar'
};
var object = {};
Object.setPrototypeOf(object, proto);
console.assert(object.foo == 'bar');