Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

`constructor` and `prototype` enumeration inconsistencies

View gist:1150670
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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');

I cover some of these inconsistencies in spotlight.js

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.

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
Something went wrong with that request. Please try again.