Skip to content

Instantly share code, notes, and snippets.

@panta82
Created March 29, 2014 14:15
Show Gist options
  • Save panta82/9855254 to your computer and use it in GitHub Desktop.
Save panta82/9855254 to your computer and use it in GitHub Desktop.
Test which characters in javascript are OK in variable names
// Easier than looking up in documentation... :-)
function test(chars) {
for (var i = 0; i < chars.length; i++) {
testSole(chars[i]);
testStart(chars[i]);
testMiddle(chars[i]);
}
function testSole(c) {
doTest(c, c, "as sole character");
}
function testStart(c) {
doTest(c, c + "good", "as starting character");
}
function testMiddle(c) {
doTest(c, "good" + c + "good", "as middle character");
}
function doTest(char, key, description) {
var ob = makeTestOb(key);
var ok = false;
try {
ok = eval("ob." + key + "();");
}
catch (err) {
}
console.log(char + " is " + (ok ? "OK" : "broken") + " " + description);
}
function makeTestOb(key) {
var res = {};
res[key] = testFn;
return res;
}
function testFn() {
return true;
}
}
test("$|~_-");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment