safari中的默认函数参数值不起作用

ctr*_* f5 12 javascript safari angularjs

我正在使用angularjs,并且null仅在safari中有任务问题.它在chrome和firefox中工作.

$scope.submit = function(id=null){
}
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

SyntaxError: Expected token ')'
Run Code Online (Sandbox Code Playgroud)

当我删除null它,它只是工作.我不知道为什么!

$scope.submit = function(id){
}
Run Code Online (Sandbox Code Playgroud)

请帮助我理解为什么这只发生在野生动物园?

Dmi*_*tin 20

Safari中尚不支持ES2015的默认参数.请检查兼容性表.

目前,基本支持提供Chrome 49和Firefox 15.


但是您可以使用以下ES5代码来实现相同的目标:

$scope.submit = function(id) {
  if (id === undefined) {
    id = null;
  }
}
Run Code Online (Sandbox Code Playgroud)