Uncaught SyntaxError: Unexpected token = in Google Chrome

此生再无相见时 提交于 2019-11-29 09:14:34
Arun P Johny

You are using a default parameter feature which is supported only by Firefox now.

function errorNotification(text) {
    text = text || "Something went wrong!";
    $.pnotify({
        title: 'Error',
        text: text,
        type: 'error'
    });
}

Javascript does not allow you to pass default arguments like that. You need to assign the default internally to the function.

function errorNotification(text) {
  text || (text = "Something went wrong!");
  $.pnotify({
      title: 'Error',
      text: text,
      type: 'error'
  });
}

Note: The other answers won't work if you have a boolean value that you want to default to true. That's because anything||true will always return true. Instead you should do something like:

function foo(bar){
  if(bar === undefined)
    bar = true;
  //rest of your function
}

function [a-zA-Z0-9_]*?\s{0,}\([^=$)]*?(=)[^)$]*?\) it can be helpful to find js functions with default parameter and then correct them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!