New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using object as key of object makes strange behavior #1282

Closed
vadjs opened this Issue Aug 7, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@vadjs

vadjs commented Aug 7, 2018

o = {};
k = {a: 1, b: 2};
o[k] = 1;
console.log(o[k]);    //1
console.log({a: 1, b: 2});  //1
k.a = 5;
console.log(o[k]);    //1
console.log({a: 1, b: 2});  //1
o[{a: 1, b: 2}] = 2
console.log(o[k]);    //2
console.log({a: 1, b: 2});  //2

Is it ECMAScript bug? Or it's "very specific" explainable mechanics?

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Aug 7, 2018

Member

Object keys can only be strings or symbols; if you do Object.keys(o) you’ll see that the object has been turned into the string ’[object Object]’.

Member

ljharb commented Aug 7, 2018

Object keys can only be strings or symbols; if you do Object.keys(o) you’ll see that the object has been turned into the string ’[object Object]’.

@ljharb ljharb closed this Aug 7, 2018

@ljharb ljharb added the question label Aug 7, 2018

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