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

时间:2022-09-11 17:09:11

I am using angularjs, and having problem with null assignment in safari only. Its working in chrome and firefox.

我使用的是angularjs,并且只在safari中存在null赋值的问题。它可以在chrome和火狐上运行。

$scope.submit = function(id=null){
}

I am getting this error

我得到了这个错误

SyntaxError: Expected token ')'

when I remove null, It just works. I don't know why !

当我删除null时,它就会工作。我不知道为什么!

$scope.submit = function(id){
}

Please help me to understand why this happening only with safari ?

请帮助我理解为什么这只发生在safari上?

1 个解决方案

#1


17  

Default parameters from ES2015 are not yet supported in Safari. Please check the compatibility table.

Safari中还不支持来自ES2015的默认参数。请检查兼容性表。

At the moment the basic support provide Chrome 49 and Firefox 15.

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


But you can use the following ES5 code to achieve the same:

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

$scope.submit = function(id) {
  if (id === undefined) {
    id = null;
  }
}

#1


17  

Default parameters from ES2015 are not yet supported in Safari. Please check the compatibility table.

Safari中还不支持来自ES2015的默认参数。请检查兼容性表。

At the moment the basic support provide Chrome 49 and Firefox 15.

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


But you can use the following ES5 code to achieve the same:

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

$scope.submit = function(id) {
  if (id === undefined) {
    id = null;
  }
}