Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooflorent/25df728008086f38a959 to your computer and use it in GitHub Desktop.
Save ooflorent/25df728008086f38a959 to your computer and use it in GitHub Desktop.
Research about instance constants
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
Copy link

mraleph commented Jan 27, 2015

  1. Yes, they have the same hidden class.
  2. No.
  3. 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