News for hackers. Stuff that matters.
Re:Google Closure: How not to write Javascript by bluebird on Thursday November 12, 2009 @06:00AM (#937510)
Hey,

goog.isString = function(val) { return typeof val == 'string'; };

var b = new String("I am also a string!"); alert(goog.isString(b)); // Will output FALSE

If that doesn't scream ignorance of the language, what does?

Re:Google Closure: How not to write Javascript by edd on Thursday November 12, 2009 @06:42AM (#937554)
For reference for anyone else who doesn't know how this should be done correctly (I had to go and look at the dojo source).

    dojo.isString = function(/*anything*/ it){
        // summary:
        // Return true if it is a String
        return (typeof it == "string" || it instanceof String); // Boolean
    }
Re:Google Closure: How not to write Javascript by dgreensp on Thursday November 12, 2009 @05:05PM (#938872)
I write a lot of JavaScript and I'm not even sure this is preferable. The "object wrappers" like String are considered deprecated in some circles as a matter of style, e.g. by Crockford. From this point of view, a stricter check is cleaner. And contrary to what the article implies, String(foo) is a cast to a primitive string, and doesn't create an object like 'new String' does.

So the Google function correctly returns whether String(foo) is a no-op.