tc39 / proposal-global

ECMAScript Proposal, specs, and reference implementation for `global`
http://tc39.github.io/proposal-global/
MIT License
349 stars 18 forks source link

Bug with JavaScript #21

Closed soroushm closed 6 years ago

soroushm commented 6 years ago

Dear Ecma,

@mohsen89z and I found a bug in JavaScript and we thought you guys might be interested:

If you put an object A as a key in object B, you can retrieve B's value with any other Object! for example:

let A = { age: 10 }
let B = {}
B[A] = 1                             // {[object Object]: 1} this is the problem!
console.log( B[A] )                  // 1
console.log( B[{}] )                 // 1 same value with different key (this is why we think it's a bug!)
console.log( B[{ age: 10 }] )        // 1 same value with different key (this is why we think it's a bug!)
console.log( B[{ age: 20 }] )        // 1 same value with different key (this is why we think it's a bug!)
console.log( B[{ year: 10 }] )       // 1 same value with different key (this is why we think it's a bug!)
ljharb commented 6 years ago

1) This isn't the repo to report such things; this is a specific proposal. 2) That's not a bug; that's because only strings and Symbols can be property keys - not objects - so when you try to use an object, it converts it to a string ("[object Object]").

What you want is a Map, which can have objects as keys.