I miss the point about regexp usage ... please tell me the difference (in a real scenario) between these two checks:
Object.prototype.toString.call(x) === Object.prototype.toString.call({}) and Object.prototype.toString.call(x).match(/\w+/g)[1] === Object.prototype.toString.call({}).match(/\w+/g)[1] finally please tell me the difference with this: Object.prototype.toString.call(x) === "[object Object]" I am usually against redundant, slow, or superflous code ... maybe I am wrong here, am I? On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ <dbj...@gmail.com> wrote: > > > This indeed woks : function isObj(o){ return > Object.prototype.toString.call(o) === '[object Object]' } > > But I do not like it ;o) It does not seem very exact somehow ... I > mean using a string literal, and all that... > I would suggest this very simple and robust little set of functions : > > // and now much simpler implementation > function isWhat(o){ return Object.prototype.toString.call(o).match(/\w > +/g)[1]; } > > function isObject(x) { return isWhat(x) === isWhat({}); } > function isArray(x) { return isWhat(x) === isWhat([]); } > function isFunction(x) { return isWhat(x) === isWhat(Function()); } > function isString(x) { return isWhat(x) === isWhat(""); } > function isNumber(x) { return isWhat(x) === isWhat(1); } > > No obfuscations here, and no "awesome" code. This seems very simple > and robust solution to me. > > --DBJ > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---