1

Possible Duplicate:
SyntaxError: Unexpected token ILLEGAL

Can someone tell me why these errors are occurring and what to do to fix them?

/*global $:false */

Blah.BlahBlah = {
  findLinks : function () {
    "use strict";

    $('a').filter(function () {
      return !(/https?:\/\/[^\/]*xyz.*/i.test($(this).attr('href')));
    }).text("***");
  ​}
};

Throws these errors in JSHint :

  • Line 10: ​} Unexpected '​'.
  • Line 11: }; Expected '}' to match '{' from line 3 and instead saw ';'.
  • Line 11: }; Missing semicolon.

Chrome console shows this error:

  • Uncaught SyntaxError: Unexpected token ILLEGAL

However, using this code (JSFiddle) in an encapsulated anonymous function does not throw an error:

/*global $:false */

(function() {

  "use strict";

  $('a').filter(function() {
    return !(/https?:\/\/[^\/]*xyz.*/i.test($(this).attr('href')));
  }).text("***");

}());
Community
  • 1
  • 1
Cofey
  • 11,144
  • 16
  • 52
  • 74
  • 1
    Jsfiddle copies an illegal character when you do a straight copy-paste from their site... Open your inspector in chrome and you'll see it. – ahren Nov 28 '12 at 20:49
  • The first example appears to work fine in the Google Chrome console. – Ivan Nov 28 '12 at 20:55

1 Answers1

1

I pasted your first fragment into jsbin and I saw a strange character before the second-to-last close brace }... possibly a normally non-printable character?

Jim Blackler
  • 22,946
  • 12
  • 85
  • 101