资产期间出错:由于Javascript函数默认参数而预编译

use*_*790 3 javascript rake ruby-on-rails

我使用Rails 4.0.0,我做rake资产:在ENV上生成预编译,并有一些错误消息:

rake aborted!
Unexpected token operator «=», expected punc «,» (line: 15816, col: 39, pos: 465171)
Error
at new JS_Parse_Error (/tmp/execjs20130828-23982-1kgxmyu.js:2357:10736)
at js_error (/tmp/execjs20130828-23982-1kgxmyu.js:2357:10955)
at croak (/tmp/execjs20130828-23982-1kgxmyu.js:2357:18665)
at token_error (/tmp/execjs20130828-23982-1kgxmyu.js:2357:18802)
at expect_token (/tmp/execjs20130828-23982-1kgxmyu.js:2357:19025)
at expect (/tmp/execjs20130828-23982-1kgxmyu.js:2357:19163)
at /tmp/execjs20130828-23982-1kgxmyu.js:2357:23402
at /tmp/execjs20130828-23982-1kgxmyu.js:2357:23466
at /tmp/execjs20130828-23982-1kgxmyu.js:2357:20786
at /tmp/execjs20130828-23982-1kgxmyu.js:2357:19536
(in ~/RubymineProjects/Hermes/app/assets/javascripts/application.js.erb)        ~/.rvm/gems/ruby-1.9.3-p448/gems/execjs-1.4.0/lib    /execjs/external_runtime.rb:68:in `extract_result'
Run Code Online (Sandbox Code Playgroud)

这种结构引发错误:函数searchHelper(myMap,coords,cond = false)但没有默认参数命令完成没有退出代码:function searchHelper(myMap,coords,cond)

它是什么?我在哪里可以阅读它?

Tom*_*ček 5

如果其他人遇到此问题,您可能已为函数参数设置了默认值,这在javascript代码中是不可能的.

无效

function hello(param = true){
  ...
}
Run Code Online (Sandbox Code Playgroud)

有效

function hello(param) {
  if (typeof param == 'undefined')
    param = true;

  ...
}
Run Code Online (Sandbox Code Playgroud)