I was just looking through some code from a few days ago and I noticed this snippet:
function getTextWidth(text, font) {
http: //stackoverflow.com/a/21015393/1413853
var canvas = getTextWidth.canvas || (getTextWidth.canvas = document
.createElement("canvas"));
var context = canvas.getContext("2d");
context.font = font;
var metrics = context.measureText(text);
return metrics.width;
}
Notice the line:
http: //stackoverflow.com/a/21015393/1413853
Which should actually be commented:
// http://stackoverflow.com/a/21015393/1413853
I would have thought that this was invalid JS syntax, yet it compiles and runs correctly in Chrome.
Is this actually meant to be used for something, or is Chrome just being lenient?
I've noticed that this works too:
function getTextWidth(text, font) {
a:
b:
c:
return 1
}