On Sun, Oct 4, 2009 at 4:53 AM, joneff <jon...@gmail.com> wrote: > It's worth noting that (!aString) is more or less equal to > (String.isUndefinedOrNullOrEmpty) than it is equal to (String.isEmpty).
It just means developers have to know the difference between "! aString" and "aString == ''". 'Don't think that changes the "reality- check" questions. > Also, since we have no type hinting, (!aString) will work easily with > objects, strings, numbers, booleans and basically everything, where as > (String.isEmpty), or any string method for that matter, should throw an > argument exception when receiving different type of arguments. Good point... although that laxness is part of the charm of javascript and (for me) is more of an advantage than a hindrance. Note, too, that by that same logic there should be functions for all sorts of native JS operators. Boolean#isFalse/isTrue, Number#add/ multiply...etc. It's a slippery slope. > At the same time (!aString/anArray.length) are perfect examples of JS > magic in use. But then, the logical question is why use > (Object.isFunction) over (typeof object === "function")? You're right, this sort of thing is always a judgement call. But to address your specific question, I see isFunction as offering several concrete advantages that isEmpty() lacks: - isFunction() is noticeably more compact than it's native counterpart - isFunction() avoids the all-too-frequent and insidious bug that happens when you misspell "function" (e.g. "typeof object == 'fuction' is always false). - it centralizes a non-trivial test that may be improved in the future. (Specifically, some platforms will return a typeof 'object' for functions defined in other windows, which breaks the current isFunction() implementation). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---