@James : thanks for this, altohugh I have to admit I am scripting (a
lot) outside of the browser context, ie, in windows scripts, so I have
not experienced this fenomenon: how can "".constructor be something
else than "function String() {...}" ?
In any case here is my code I am using for is<T>() functionality. And
it works for me.
Although I can not swear I ever tested this inside <iframe> ?
I hope this might give some idea to good jQuery developers, when
battling with javascript type system ;o)

--DBJ


    // String.trim() ECMA5
    if ("function" !== typeof "".trim)
        String.prototype.trim = function() { return this.replace(/^\s+|
\s+$/g, ''); }

    // type discovery helpers avoiding the 'typeof' usage
    dbj.isWhat = function(x) {
        return ("" + x.constructor).split("(")[0].split("function")
[1].trim();
    }

    // is<T>() function generator
    dbj.isWhat.gener = function(names, root) {
        for (var n in names) {
            root["is" + names[n]] = Function("x", " return dbj.isWhat
(x) === '" + names[n] + "'")
        }
    }

    // generate is<T>() functions by using constructor names
    // which are capitalised vs type names
    dbj.isWhat.gener(["Array", "Object", "Function", "String",
"Number"], dbj)

    // TESTING
    // USAGE: dbj.isWhat.test()
    dbj.isWhat.test = function() {
        function E(S) { return "\n" + S + "\t--> " + eval(S); }

        function T(X) {
            return E('dbj.isArray(' + X + ')') + E('dbj.isObject(' + X
+ ')') +
          E('dbj.isFunction(' + X + ')') +
          E('dbj.isString(' + X + ')') + E('dbj.isNumber(' + X + ')');
        }
        var s = "";
        for (var n in { '[]': 1, '{}': 2, 'Function()': 3, "''": 4,
"1": 5 })
            s += "\n" + T(n);
        return s;
    }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to