Youtube uses "default" as a name for an object property Youtube uses "default" as a name for an object property json json

Youtube uses "default" as a name for an object property


An Identifier is not the same as a PropertyName.

PropertyName need 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:

 PropertyName :         Identifier         StringLiteral         NumericLiteral

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.


The compiler might be flagging this up due to cross-browser compatibility issues.

I hit the same thing recently with both default and extends when creating a template library which uses code instead of parsing text. The code worked just fine, but the Closure Compiler complained about those keywords when used as properties... then I tried it in IE:

>>> var o = {default: 'test'}SyntaxError: Expected identifier, string or number>>> var o = {'default': 'test'}>>> o.defaultSyntaxError: Expected identifier