lundi 16 février 2015

How does directly setting the [[Prototype]] on an object defeat optimization?


I understand the following is frowned upon based on its difficulty to optimize (please correct me if I am wrong).


How does this defeat optimization in JavaScript compilers? Is it related to the internal object "classes" present inside V8?



function Parent() {}
function Child() {}

Child.prototype = (function () {
var o = {};
o.__proto__ = Parent.prototype;
return o;
}());


Or is it just that __proto__ is a de facto standard that is historically browser-peculiar that makes this approach poor?


Note: I am aware of the correct methods for configuring prototype-chains; this is a thought experiment.





Aucun commentaire:

Enregistrer un commentaire