Create a gist now

Instantly share code, notes, and snippets.

`constructor` and `prototype` enumeration inconsistencies
function Constructor() {
this.constructor = this.prototype = 1;
}
Constructor.prototype.constructor = 1;
// Sanity checks. The first will fail in IE < 9 due to the JScript `[[DontEnum]]` bug.
console.assert(new Constructor().propertyIsEnumerable('constructor'),
'The `constructor` instance property should be enumerable');
console.assert(new Constructor().propertyIsEnumerable('prototype'),
'The `prototype` instance property should be enumerable');
// Fails in Opera 11.50.
console.assert(!Constructor.propertyIsEnumerable('prototype'),
'The `Constructor.prototype` property should not be enumerable');
// Overwriting the `constructor` property should reset its internal `[[Enumerable]]` property to
// `true`, since `[[Configurable]]` is `false`. Fails in latest WebKit nightly, Google Chrome
// Canary, Firefox 6, IE < 9, and Opera 11.50.
console.assert(Constructor.prototype.propertyIsEnumerable('constructor'),
'The overwritten `constructor` prototype property should be enumerable');
Constructor.prototype = {
constructor: 1
};
// Overwriting the `prototype` property should *not* reset its internal `[[Enumerable]]` attribute,
// since its `[[Configurable]]` attribute is `false`. Fails in Opera.
console.assert(!Constructor.propertyIsEnumerable('prototype'),
'The overwritten `Constructor.prototype` property should not be enumerable');
// Fails in IE < 9 due to the JScript `[[DontEnum]]` bug.
console.assert(Constructor.prototype.propertyIsEnumerable('constructor'),
'The overwritten `constructor` property of the overwritten prototype should be enumerable');
@jdalton
jdalton commented Aug 17, 2011

I cover some of these inconsistencies in spotlight.js

@jdalton
jdalton commented Aug 17, 2011

Safari and Opera incorrectly set a function's prototype property to [[Enumerable]] true and because the prototype property is [[Configurable]] false, it will not allow it to be changed.

@kitcambridge
Owner

@jdalton Updated the Gist. Thanks! That explains the prototype inconsistencies, but not the constructor deviations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment