4

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_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?

leppie
118k18 gold badges201 silver badges300 bronze badges
asked Jan 21, 2012 at 14:33

4 Answers 4

6

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

answered Jan 21, 2012 at 14:35
Sign up to request clarification or add additional context in comments.

4 Comments

what does you mean with that? because the problem seems to be the "-" since I tried replacing the "-" with "_" and it seems to work :)
Yes, @alisnehx, that's right. JavaScript does not allow "-" in identifiers.
Thank you..It seems I have a big problem then since I have an auto-generated long code with cxf apache from wsdl to js..So it's impossible traying to replace manyally everyone of them!
@alisnehx You will have to alter the code generation tool, or write a short program that alters the auto-generated output.
5

You cannot use hyphens in JavaScript function names:

function www_ebest_eu_company_node_service_task-slot-info () {
// Should proabbly be
function www_ebest_eu_company_node_service_task_slot_info () {
//---------------------------------------------^^^^^^^^
answered Jan 21, 2012 at 14:36

1 Comment

Oh yes thank you! I notice it in fact,so there is no way on accepting the "-" like a part of the function's name?
3

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.

answered Jan 21, 2012 at 14:37

Comments

2

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

answered Jan 21, 2012 at 14:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.