You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list when using arrow functions as public field declarations (TC39 proposal) -- Safari
#16
Open
Nashorn opened this issue
Oct 8, 2020
· 0 comments
Safari 13 and below does not support public class field declarations on classes. Ex:
class T {
foo = () => {
//syntax error
}
}
Copy and run that in Safaris console; will throw a syntax error:
"SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list."
Nashorn
changed the title
Arrow functions and/or public fields declarations (TC39 proposal) not supported in Safari until v14
Arrow functions and/or public field declarations (TC39 proposal) not supported in Safari until v14
Oct 8, 2020
Nashorn
changed the title
Arrow functions and/or public field declarations (TC39 proposal) not supported in Safari until v14
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list. Arrow functions and/or public field declarations (TC39 proposal) not supported in Safari until v14
Oct 8, 2020
Nashorn
changed the title
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list. Arrow functions and/or public field declarations (TC39 proposal) not supported in Safari until v14
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list when using arrow functions as public field declarations (TC39 proposal) -- Safari until v14
Oct 8, 2020
Nashorn
changed the title
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list when using arrow functions as public field declarations (TC39 proposal) -- Safari until v14
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list when using arrow functions as public field declarations (TC39 proposal) -- Safari
Oct 8, 2020
Safari 13 and below does not support public class field declarations on classes. Ex:
Copy and run that in Safaris console; will throw a syntax error:
"SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list."
See TC39 Proposal:
https://github.com/tc39/proposal-class-fields
Safari 14 beta does have support. Work around is to use ES6 working method syntax:
The benefit of arrow functions on classes is to preserve scope reference to [this] without having to .bind() your methods.
Example:
Will alert undefined, because foo() will run in scope of document object which has no .desc property. But with arrow functions:
WORK AROUND SOLUTION:
It works as you would expect. Now, to use the normal working method syntax and keep your reference to [this], you'll have to bind():
The text was updated successfully, but these errors were encountered: