JavaScript’s String Identity Method is Not Trivial

This bit of JavaScript confused me. This is tested on Gecko’s JavaScript engine only.

String.prototype.i  = function() { return this; }
String.prototype.i2 = function() { return this+""; }
typeof("a string".i())  == "string" // => false
typeof("a string".i2() == "string" // => true
Advertisements
%d bloggers like this: