JS __proto__ Shenanigans
I can't believe it, every time some cool pattern comes into games,
While is possible to define such properties in ES5, this is the classic good old IE only scenario we all remember:
As a property, we should not have any special case, able of these kind of problems, while we should all keep using
So now you know ;)
__proto__
makes everything pointless, in a trusted meaning of a generic property! Previously, in Internet Explorer
One of the biggest and most known WTFs in IE is the fact thatObject.prototype
properties are not enumerable.While is possible to define such properties in ES5, this is the classic good old IE only scenario we all remember:
As simple as that, all native properties in the main prototype were considered
for(var key in {toString:"whatever"}) {
alert(key); // never in IE
}
{toString:true}.propertyIsEnumerable("toString") === false
because indeed, these were not enumerating (just in case: enumerable properties are those that should show up in a for/in loop)The Same Mistake With __proto__ If Not Worse
That's correct, the moment you play with this property name things start falling a part same old IE way or even worst.Not only enumerability, but also the
alert(
{__proto__:"whatever"}.
propertyIsEnumerable(
"__proto__"
) // this is false !!!
);
hasOwnProperty(key)
is gone!
var o = {};
o.__proto__ = 123;
o.hasOwnProperty("__proto__");
// false !!!
Do Not Use Such Mistake
Even if part of new specs,__proto__
is showing off all its anti pattern problems we all laughed about when it was IE only.As a property, we should not have any special case, able of these kind of problems, while we should all keep using
Object.statics()
function that works internally, rather than on property name level.So now you know ;)
Comments
Post a Comment