最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Default function parameter value in safari is not working - Stack Overflow

programmeradmin1浏览0评论

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

$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 !

$scope.submit = function(id){
}

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

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

$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 !

$scope.submit = function(id){
}

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

Share Improve this question edited Apr 25, 2016 at 13:22 GRESPL Nagpur asked Apr 25, 2016 at 13:06 GRESPL NagpurGRESPL Nagpur 2,0983 gold badges23 silver badges42 bronze badges 1
  • 4 Default function parameter values are an ES2015 feature that Safari apparently does not support. – Pointy Commented Apr 25, 2016 at 13:09
Add a comment  | 

1 Answer 1

Reset to default 20

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

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


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

$scope.submit = function(id) {
  if (id === undefined) {
    id = null;
  }
}
发布评论

评论列表(0)

  1. 暂无评论