Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

javascript - SyntaxError: Invalid character 'u8203'

This function gives me the following error:

SyntaxError: Invalid character 'u8203'

All looks good to me,

function changeColumnWidth() {
    var w = Math.random() * 200+80;
    $('#menu').css("width", w+"px");
}?

can someone spot the error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's a character after the closing curly brace:

I copy-pasted your code in Firefox' console, postfixed with a undefined method invocation:

'function changeColumnWidth() {
    var w = Math.random() * 200+80;
    $('#menu').css("width", w+"px");
}?'.l(); /* .l() triggers a TypeError, since it's not defined */

A TypeError (undefined) shows up, which includes the parsed (escaped) code:

TypeError: "function changeColumnWidth() { var w = Math.random() * 200+80; $('#menu').css("width", w+"px");}u200B".l is not a function.
                                 ^^^^^^ Here's the error.

Now, the troublemaker is found. To fix it, open your code in a text editor, and remove the invisible character. This character can be detected by walking through all characters using the arrow keys.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...