Last active
August 29, 2015 14:14
-
-
Save ooflorent/25df728008086f38a959 to your computer and use it in GitHub Desktop.
Research about instance constants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Obj(x) { | |
if (typeof x !== 'number') throw new Error() | |
Object.defineProperty(this, 'x', {value: x}) | |
} | |
var a = new Obj(1) | |
var b = new Obj(2) | |
// Do `a` and `b` have the same hidden class in v8? | |
// | |
// Does the above definition impact performances? | |
// | |
// From a performance point of view, is it worth | |
// locking (using `defineProperty`) prototype's defs? |
mraleph
commented
Jan 27, 2015
- Yes, they have the same hidden class.
- No.
- Yes, for constants on prototype objects, except functions - those are already treated in a special way. V8 does not use it as much as it could, but I would expect it to start using it more and more in the future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment