I’ve been using the Youtube json api for making a new mash-up.
Somewhere in the response you can find the following:
{
"player":
{
"default":"http://www.youtube.com/watch?v\u003deH5Iysm417U"
}
}
I’ve always learned not to use any words mentioned in the reserved words section of the ECMAScript standard as identifiers. So as far as I know it’s not allowed to use the name “default” as a property name. Why is Youtube doing this?
player.default
To be honest, the above code works fine in a browser. But I had to change it to the code beneath in order to have no compile errors when using the Google closure compiler.
player["default"]
It just feels wrong.
The most important question here is, can I do anything about it?
An
Identifieris not the same as aPropertyName.PropertyNameneed only not consist of reserved words when declared without quotes. When declared with quotes, then all strings are valid, even" ".Here is the list of the valid productions:
http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf, 11.1.15
You cannot change the response from Youtube, and allthough there is nothing wrong with
player.default, you will simply need to use the [] accessor if you want to avoid this error in the closure compiler.But really, this is a bug with the compiler, not the javascript.