Skip to content Skip to sidebar Skip to footer

Javascript Safari - Syntaxerror: Unexpected Token '>'

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: windo

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){returnString.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.

Solution 3:

The problem is with the arrow function syntax from es6 as Jerry Zhu already mentioned.

To support older browsers you need to replace "response => {" with "function(response) {" and also "setTimeout(() => {" with "setTimeout(function() {".

Solution 4:

Advice for you to be quiet with all browsers ...

  1. Avoid using the VAR => RESULT VAR, prefer function (VAR) {return RESULT VAR;}

  2. Never use parameters in your codes with values ​​like: function (VAR = DEFAULTVALUE) {} Use function (VAR) {if (VAR == "undefined") VAR = DEFAULTVALUE;}

  3. To get an object: document.getelementByID

  4. To specify an uninitialized property, choose Object.setAttribute (property, value) rather than Object.property = value. This can lead to errors or inappropriate behavior.

Some Styles properties can only be used if you set them up, especially the CSS3. Javascript accepts the same thing as CSS provided that you respect its usage.

  1. to get DOM coordinates browsers from Netscape X and IE or other browser Opéra, FireFox, Apple X, etc...

this.Ypos = document.body.scrollTop + ((! this.IE)? e.pageY: (window.event.y)); this.Xpos = document.body.scrollLeft + ((! this.IE)? e.pageX: (window.event.x)); If coordinates smartphones Event page.X is : Event.changedTouches[e.changedTouches.length-1].pageX;

  1. To print an object in document: Object.appendChild (mebox)

I'm 53 years old, I've been working on the Internet for 35 years and since then nothing has really changed.

Post a Comment for "Javascript Safari - Syntaxerror: Unexpected Token '>'"