简体   繁体   English

语法错误:意外令牌“ - ”

[英]Syntax error: unexpected token “-”

I'm doing a web application, and when I started writing the code in JavaScript I'm getting this error: 我正在做一个Web应用程序,当我开始用JavaScript编写代码时,我收到了这个错误:

Syntax error: unexpected token "-"  javascript 

I'm using Aptana Studio 3. I thought it was Aptana's problem, so then I tried with Eclipse, but still got the same error. 我正在使用Aptana Studio 3.我认为这是Aptana的问题,所以我尝试使用Eclipse,但仍然遇到了同样的错误。 Eclipse shows me this error: Eclipse向我显示了这个错误:

Cannot return from outside a function or method.

Here's my function: 这是我的功能:

function www_ebest_eu_company_node_service_task-slot-info () {
    this.typeMarker = 'www_ebest_eu_company_node_service_task-slot-info';
    this._endDateTime = null;
    this._number = null;
    this._orderId = null;
    this._startDateTime = null;
    this._taskId = null;
    this._taskStatus = null;
}

I have many functions like this, and for every of them I'm getting the same error. 我有很多这样的功能,对于每一个我都得到同样的错误。

Does anyone have the same problem? 有没有人有同样的问题?

www_ebest_eu_company_node_service_task-slot-info不是有效的JavaScript标识符。

You cannot use hyphens in JavaScript function names: 您不能在JavaScript函数名称中使用连字符:

function www_ebest_eu_company_node_service_task-slot-info () {

// Should proabbly be
function www_ebest_eu_company_node_service_task_slot_info () {
//---------------------------------------------^^^^^^^^

A hyphen "-" is not a valid character for naming variables or functions. 连字符“ - ”不是命名变量或函数的有效字符。 The hyphen is used for arithmetic, subtraction, and not for naming variables. 连字符用于算术,减法,而不用于命名变量。 You can replace the hyphens with underscores or go with a CamelCase notation. 您可以使用下划线替换连字符,也可以使用CamelCase表示法。

Dashes are not allowed in identifier (function, variables, etc) names. 标识符(函数,变量等)名称中不允许使用破折号。 Stay consistant with underscores or camelCase. 与下划线或camelCase保持一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM