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

javascript - Syntax error: unexpected token "-" - Stack Overflow

programmeradmin4浏览0评论

I'm doing a web application, and when I started writing the code in JavaScript I'm getting this error:

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. Eclipse shows me this error:

Cannot return from outside a function or method.

Here's my function:

function www_ebest_eu_pany_node_service_task-slot-info () {
    this.typeMarker = 'www_ebest_eu_pany_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?

I'm doing a web application, and when I started writing the code in JavaScript I'm getting this error:

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. Eclipse shows me this error:

Cannot return from outside a function or method.

Here's my function:

function www_ebest_eu_pany_node_service_task-slot-info () {
    this.typeMarker = 'www_ebest_eu_pany_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?

Share Improve this question edited Jan 21, 2012 at 15:06 leppie 117k18 gold badges200 silver badges300 bronze badges asked Jan 21, 2012 at 14:33 TotoroTotoro 1562 silver badges13 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

www_ebest_eu_pany_node_service_task-slot-info is not a valid JavaScript identifier.

You cannot use hyphens in JavaScript function names:

function www_ebest_eu_pany_node_service_task-slot-info () {

// Should proabbly be
function www_ebest_eu_pany_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.

Dashes are not allowed in identifier (function, variables, etc) names. Stay consistant with underscores or camelCase.

发布评论

评论列表(0)

  1. 暂无评论