JavaScript Safari - SyntaxError: Unexpected token '>'
10,972
Solution 1
Arrow function ()=>{} is es6 feature, firefox and chrome both are already supported. But safari old version doesn't. Please check http://kangax.github.io/compat-table/es6/ for more information.
Solution 2
Safari 5.1 is really bad !!!
Example it does not load with =>
var t=w.map(v => String.fromCharCode(v));
Replacement it will take charge
var t=w.map(function(v){return String.fromCharCode(v)});
To make a script work on all browsers, avoid,
- The
=>
and preferfunction () {}
instead - The
function (param = x) {}
, preferfunction (param) {if (param == 'undefined') {param = x;}}
- The
let
and usevar
instead.
Related videos on Youtube
Author by
playnic
Updated on September 15, 2022Comments
-
playnic over 1 year
I have the problem that this JavaScript snippet runs in Firefox / Chrome without any problem, and Safari I get error: "SyntaxError: Unexpected token '>'".
Here's the code:
window.onclick = (test) => { const googleWindow = window.open(); fakeAjax(response => { googleWindow.location.replace(`https://google.com?q=${response}`); }); }; function fakeAjax(callback) { setTimeout(() => { callback('example'); }, 1); }
I've googled and have already seen here in the forum, the problem there appears often, unfortunately I have not found a suitable solution.
Thank you in advance Best regards
-
Pupil almost 7 yearsBut, what should be the solution?