![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Just nailed down a spurious bug from a 3rd party code which seems to be in unexpected continuation of "Little Help with JavaScript" side discussion and Mr.Cornford comments: http://groups.google.com/group/comp.lang.javascript/msg/ff0101e295265cb5 The minified test case: var test = { op1 : false, op2 : false, default: false } window.alert(test.default); Leads to the syntax error on all test set browsers but Firefox where it expectedly (? unexpectedly ?) reports that test.default = false |
|
The others (IE, Safari, Chrome, Opera) do consider such code as a broken switch-case construction so reporting the missing switch clause. By taking default key into quotes such reading goes away: var test = { op1 : false, op2 : false, 'default': false } window.alert(test.default); // false I honestly don't give a damn what ECMA says on it, |
|
A conforming implementation of ECMAScript is permitted to support program and regular expression syntax not described in this specification. |
#3
| |||
| |||
|
|
Just nailed down a spurious bug from a 3rd party code which seems to be in unexpected continuation of "Little Help with JavaScript" side discussion and Mr.Cornford comments: http://groups.google.com/group/comp.lang.javascript/msg/ff0101e295265c b5 The minified test case: var test = { op1 : false, op2 : false, default: false } window.alert(test.default); Leads to the syntax error on all test set browsers but Firefox where it expectedly (? unexpectedly ?) reports that test.default = false The others (IE, Safari, Chrome, Opera) do consider such code as a broken switch-case construction so reporting the missing switch clause. By taking default key into quotes such reading goes away: var test = { op1 : false, op2 : false, 'default': false } window.alert(test.default); // false I honestly don't give a damn what ECMA says on it, it sucks even carved somewhere on a stone. With this and the preceding label vs key issue the safe coding policy will be changed: it will be required in the office and from subcontractors to use explicit quoting of object key values and do not ever relay on the implicit one. The group readers may or may not account this coding advise. |
#4
| |||
| |||
|
|
... By taking default key into quotes such reading goes away: var test = { op1 : false, op2 : false, 'default': false } window.alert(test.default); // false I honestly don't give a damn what ECMA says on it, it sucks even carved somewhere on a stone. With this and the preceding label vs key issue the safe coding policy will be changed: it will be required in the office and from subcontractors to use explicit quoting of object key values and do not ever relay on the implicit one. The group readers may or may not account this coding advise. |
#5
| ||||||||||
| ||||||||||
|
|
Just nailed down |
|
a spurious bug from a 3rd party code which seems to be in unexpected continuation of "Little Help with JavaScript" side discussion and Mr.Cornford comments: http://groups.google.com/group/comp.lang.javascript/msg/ff0101e295265cb5 The minified test case: var test = { op1 : false, op2 : false, default: false ^^^^^^^ |
|
} window.alert(test.default); Leads to the syntax error on all test set browsers but Firefox where it expectedly (? unexpectedly ?) reports that test.default = false |
|
The others (IE, Safari, Chrome, Opera) do consider such code as a broken switch-case construction |
|
so reporting the missing switch clause. |
|
By taking default key into quotes such reading goes away: |
|
var test = { op1 : false, op2 : false, 'default': false } window.alert(test.default); // false I honestly don't give a damn what ECMA says on it, |
|
it sucks even carved somewhere on a stone. |
|
With this and the preceding label vs key issue the safe coding policy will be changed: it will be required in the office and from subcontractors to use explicit quoting of object key values and do not ever relay on the implicit one. |
|
The group readers may or may not account this coding advise. |
#6
| |||
| |||
|
|
Just nailed down a spurious bug from a 3rd party code which seems to be in unexpected continuation of "Little Help with JavaScript" side discussion and Mr.Cornford comments: *http://groups.google.com/group/comp.lang.javascript/msg/ff0101e295265cb5 The minified test case: *var test = { * op1 : false, * op2 : false, * default: false *} window.alert(test.default); Leads to the syntax error on all test set browsers but Firefox where it expectedly (? unexpectedly ?) reports that test.default = false Whereas the error is not caused by the window.alert(...) call, of course. The others (IE, Safari, Chrome, Opera) do consider such code as a broken switch-case construction so reporting the missing switch clause. By taking default key into quotes such reading goes away: * var test = { * op1 : false, * op2 : false, * 'default': false *} window.alert(test.default); // false I honestly don't give a damn what ECMA says on it, |
|
`default' is a keyword; it may not be used as identifier in an ECMAScript-3 compliant /Program/ (ES3F, 7.5.2). *And when not a /StringLiteral/ or a /NumericLiteral/, the name part in an /ObjectLiteral/ must be an /Identifier/ (ES3F, 11.1.5). |
#7
| |||
| |||
|
|
VK wrote on 24 okt 2009 in comp.lang.javascript: snip I honestly don't give a damn what ECMA says on it, it sucks even carved somewhere on a stone. With this and the preceding label vs key issue the safe coding policy will be changed: it will be required in the office and from subcontractors to use explicit quoting of object key values and do not ever relay on the implicit one. The group readers may or may not account this coding advise. "> Just nailed down ... " ?? The writer of Jason knew this already, [that keys should but do not always condone reserved words] it was the reason that he required all keys to be quoted. |
#8
| |||
| |||
|
|
(Incidentally, the "office" delusion is interesting, as you are such an appalling programmer that it is literally increasable to suggest that you have any colleagues that are capable of programming at all and that you maintain employment in such an environment.) |
#9
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: `default' is a keyword; it may not be used as identifier in an ECMAScript-3 compliant /Program/ (ES3F, 7.5.2). And when not a /StringLiteral/ or a /NumericLiteral/, the name part in an /ObjectLiteral/ must be an /Identifier/ (ES3F, 11.1.5). Do you understand the difference between literal values and string values? One cannot have var class = 'foo'; but it is perfectly OK to have myObject['class'] = 'foo'; |
|
'default' in the quoted context is a string to use as key name, |
#10
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: `default' is a keyword; it may not be used as identifier in an ECMAScript-3 compliant /Program/ (ES3F, 7.5.2). And when not a /StringLiteral/ or a /NumericLiteral/, the name part in an /ObjectLiteral/ must be an /Identifier/ (ES3F, 11.1.5). Do you understand the difference between literal values and string values? One cannot have var class = 'foo'; but it is perfectly OK to have myObject['class'] = 'foo'; |
|
'default' in the quoted context is a string to use as key name, |
![]() |
| Thread Tools | |
| Display Modes | |
| |