-1

I am trying to fix character mappings on paste within a text area element using the following object to match characters.

var replacementMap = {
    String.fromCharCode(61607) : String.fromCharCode("9632"),  //solid box
    String.fromCharCode(61623) : String.fromCharCode("9679"),  //solid circle
    String.fromCharCode(61656) : String.fromCharCode("9654"),  //right arrow
    String.fromCharCode(61692) : String.fromCharCode("10003"), //checkmark
    String.fromCharCode(61558) : String.fromCharCode("10070")  //black diamond minus white X
};

This object is called from a regular expression to change the characters within a string based on the character codes but currently firebug is throwing the following error:

SyntaxError: missing : after property id
String.fromCharCode(61607) : String.fromCharCode("9632"),  //solid
Jeremy
  • 3,620
  • 9
  • 43
  • 75

2 Answers2

2

You can't use function/method calls as object literal keys. You'll want something like:

var replacementMap = {};

replacementMap[ String.fromCharCode(61607) ] = String.fromCharCode("9632");  //solid box
replacementMap[ String.fromCharCode(61623) ] = String.fromCharCode("9679");

// etc.
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
2

If you just want the object to compile, you could do like this instead:

var replacementMap = {};

replacementMap[String.fromCharCode(61607)] = String.fromCharCode("9632");  //solid box
replacementMap[String.fromCharCode(61623)] = String.fromCharCode("9679");  //solid circle
replacementMap[String.fromCharCode(61656)] = String.fromCharCode("9654");  //right arrow
replacementMap[String.fromCharCode(61692)] = String.fromCharCode("10003"); //checkmark
replacementMap[String.fromCharCode(61558)] = String.fromCharCode("10070");  //black diamond minus white X

But they are right - it's not an array! :)

hasse
  • 883
  • 2
  • 10
  • 24