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,

  1. The => and prefer function () {} instead
  2. The function (param = x) {}, prefer function (param) {if (param == 'undefined') {param = x;}}
  3. The let and use var instead.
Share:
10,972

Related videos on Youtube

playnic
Author by

playnic

Updated on September 15, 2022

Comments

  • playnic
    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
    Pupil almost 7 years
    But, what should be the solution?