Closed
Bug 696255
Opened 13 years ago
Closed 12 years ago
object.prototype ruined with watch and unwatch
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 774645
People
(Reporter: smartj, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Build ID: 20110928134238
Steps to reproduce:
Mozilla broke Prescreen.com by adding "watch" to the object prototype.
Many JavaScript users will use {} as as key/value data-type. I used {} to store names of the elements I was putting inside of a collection. One of these elements happened to have a user-defined name of "watch."
var elements = {};
...
if (!elements['watch']) {
elements['watch'] = element;
}
Actual results:
Native objects have "watch" and "unwatch" symbols attached to them, which breaks code.
Expected results:
There are millions of JavaScript programs that rely on {} to have a clean prototype. Deciding for these users that "watch" and "unwatch" are suitable "extensions" is a poor implementation decision. Mozilla is taking a gamble that this extremely common symbol name will not result in a namespace collision.
If default extensions are required, please consider a namespace such as __SYMBOL__, which will not likely be used by ordinary users.
Reporter | ||
Comment 1•13 years ago
|
||
Here is the documentation of "watch"
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/watch
Reporter | ||
Comment 2•13 years ago
|
||
Other examples of users being confused by this "gotcha" introduced by Mozilla:
http://stackoverflow.com/questions/3269812/how-can-i-use-the-string-watch-as-a-key-in-a-javascript-associative-array
http://blog.ryanrampersad.com/2010/06/25/missing-argument-1-when-calling-function-mutator-call/
Comment 3•13 years ago
|
||
watch/unwatch are **** and on the way out. However, what you are doing is colliding with other standard names as well. The right way of using objects as a hash map is:
var map = Object.create(null);
That way you won't pollute your map with prototype properties.
If you want to get rid of watch immediately, we should take that to the dev-platform mailing list. I think its hard because it will break web content. We have to do it slowly and carefully. The rest of your bug is more on your side I think, so I will close this as invalid. Use the code above instead.
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
Reporter | ||
Comment 4•13 years ago
|
||
I disagree w/ this resolution. Object.create was introduced in JavaScript 1.8.5, and I *could* use Object.create(null) if I knew that my scripts were always being invoked in JS 1.8.5. What is the suggested solution for the other 90% of users who are not running JavaScript 1.8.5?
It seems to me that Object.create fixes the issue by just making it worse -- adding additional symbols to the root prototype and requiring detection code to work-around.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Updated•12 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago → 12 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•