Expressions with slashes are highlighted incorrect

2019-07-02 21:12发布

问题:

First off: I'm not talking about multi line commenting, I don't think. The problem is occurring when there is a space between the / and the * such as

draw.arc(x, y, radius, Math.PI/2, Math.PI/2, true);

In dreamweaver, the text

/2,Math.PI/

Goes green.

I've googled but to no avail. I'm sure it's something dumb but I'm stumped.

Also note: still occurs when the Math.PI formula is defined as a variable

回答1:

Dreamweaver is interpreting that as a regex for syntax highlighting.

The regex notation /regex/ is the most notoriously difficult part to parse in all of Javascript.

Your code is fine. You could try adding spaces around the /. I've often seen that work.



回答2:

As stated below, it's a parsing issue with Dreamweaver - interpreting your syntax as a regular expression.

A solution to this problem would be to create a variable for that value. Additionally, it's more efficient than doing the same operation more than once.

var piOver2 = Math.PI / 2;

draw.arc(x, y, radius, piOver2, piOver2, true);


回答3:

It is something dumb: Dreamweaver has a bug in it. Your code must still execute. That is a perfectly valid sequence of characters, that does not result in a comment.