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

javascript - Firefox console getting 'SyntaxError: illegal character - Stack Overflow

programmeradmin2浏览0评论

My script is as follows:

<script>
    var lastTime = 0; 
    function loop(time) {
        console.log(time);
        var delay = time–lastTime; 
        var fps = 1000/delay; 
        console.log(delay + ' ms');
        updateAnimation(); 
        mozRequestAnimationFrame(loop); 
        lastTime = time;
        } 
    //loop(200000);
    requestAnimationFrame(loop);
</script>

When I run it under firefox with the Web console feature - I get:

SyntaxError: illegal character

on the line

var delay = time–lastTime;

Whats wrong with that line?

My script is as follows:

<script>
    var lastTime = 0; 
    function loop(time) {
        console.log(time);
        var delay = time–lastTime; 
        var fps = 1000/delay; 
        console.log(delay + ' ms');
        updateAnimation(); 
        mozRequestAnimationFrame(loop); 
        lastTime = time;
        } 
    //loop(200000);
    requestAnimationFrame(loop);
</script>

When I run it under firefox with the Web console feature - I get:

SyntaxError: illegal character

on the line

var delay = time–lastTime;

Whats wrong with that line?

Share Improve this question asked Dec 4, 2013 at 10:04 BushBush 2,5335 gold badges36 silver badges59 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

Your dash is character code U+2013, also called em dash, translated to an HTML entity it would be &ndash;.

You should use the normal U+002D or a hyphen minus.

This site has a lot of good information for you regarding this.

You probably copy pasted this from a WordPress blog or another website that translates characters into "pretty characters". Switch the character out with a dash instead -.

It looks as though the dash in

var delay = time–lastTime;

isn't a minus sign. Try replacing it with -.

You copied and pasted from somewhere. Try using the -(minus) symbol. Because time–lastTime doesn't contain minus symbol

time-lastTime; // use - (minus) sybmol
发布评论

评论列表(0)

  1. 暂无评论