• spaceman (unregistered)

    waiting for frist, I shall return

  • bvs23bkv33 (unregistered)

    Julio is first

  • spaceman (unregistered)

    Tell Julio to read this!


  • Quite (unregistered)

    ... and don't forget the good old favourite of initialising it to false, and then setting it to false.

    Maybe the writer of this code wanted the ability to put some internal debugging into the method, and so assigned the value of the function to a boolean so as to be able to put it into an alert. After all, it's important to check it returns "false" when the function is "undefined". The sky might fall otherwise.

  • Foobar (unregistered) in reply to spaceman

    Stephen, did you forget to take your meds?

  • Brian (unregistered)

    Oh, it's probably simple: long ago, some clever coder set up a table of function-pointers (or the equivalent in JS) somewhere as a plugin-type inner platform layer and needed a way to denote the ones that weren't set. So, taking advantage of type fluidity, he picked this "undefined" constant rather than something sensible like, say, null. Then, much later, some not-so-clever coder saw several calls to this mysterious IsFunction and decided that it seemed like a good idea to use it for general defensive coding. And thus a cargo cult is born.

  • my name is missing (unregistered)

    I feel like creating an IsFunction repo on GitHub. Surely everyone needs to depend on this.

  • spaceman (unregistered)

    Oh I'm long past the point of no returns for meds. The doctors just tell me to stay indoors, and don't walk in public without your leash!

  • Andrew (unregistered) in reply to my name is missing

    No, put it on npm. Make sure it pulls in a few dozen dependencies "just because". When the entire internet uses it, try to delete the repo and watch it all burn.

  • spaceman (unregistered)

    Quick two questions for the experts:

    1. How can I get this tweet read by the following people? Madonna, Ashley Judd, Linda Sarsour, Medea Benjamin, etc. etc. ? https://twitter.com/fun_stevehawkin/status/966651703511736320

    2. Will the C&S guys be interested in a multi college fellowship regarding school violence prevention for their highly ironic 4-20 drug use marathon against mental illness?

  • Sole Purpose of Visit (unregistered) in reply to Andrew

    That, I feel, would be a rather fine experiment. Make it so!

  • Sole Purpose of Visit (unregistered) in reply to spaceman

    Did they also recommend unplugging your computer? Because, they should.

  • Carl Witthoft (google) in reply to my name is missing
    I feel like creating an IsFunction repo on GitHub. Surely everyone needs to depend on this.
    That's CompletelyInsufficient(TM). You need an "Is" repo. It must include IsFunction, IsInteger, IsString, IsDouble, IsNotFunction, IsNotInteger, IsNotString, IsNotDouble, IsMyIpAddress,... you get the idea.
  • Zenith (unregistered)

    The real WTF is JavaScript. Oh how I loathe weakly-typed languages. You have to write so much more defensive code, especially when they do weird type coercions.

    I was having trouble yesterday with getAttribute() and setAttribute(). Apparently, passing a string into the latter doesn't guarantee it'll come back out as a string with the former in IE (there's an optional flag to force strings). Thus when I was saving "11" and expecting to pass "11" into a function to get 11 for another function that need an integer, it just stopped executing. While trying to figure out what was going on, I saw how much code like IsFunction() that I had added to so many calls. This type of idiocy is rarely necessary in a real language.

  • spaceman (unregistered)

    Please see:


    Don't click links! XSS is dangerous!

    • Flying Copypasta Monster
  • not a robot (unregistered)

    wow, finally something amusing again. no made up booring backround story which just wastes 15 minutes of your life. good old wtf like those for which i started reading this site.

  • spaceman (unregistered)

    Wow, he's funny!


  • David (unregistered) in reply to my name is missing

    "I feel like creating an IsFunction repo on -GitHub- npm. Surely everyone needs to depend on this." FTFY (also, I don't know how formatting works)

  • DrOptableUser (nodebb) in reply to Zenith

    The weekly-typed will inherit the Earth. Then an inner platform of types will rise to power to rule them.

  • 🤷 (unregistered)

    How come that spaceman's links never seem to be held for moderation? Wild conspiracy theory: spaceman is REMY PORTER!

  • Andrew A. Gill (unregistered)

    For some reason, I suspect there's some backstory on this, like a boss insisting that "All function calls must be verified before being executed" or some such.

    The poor coder probably whipped this up and either never tested it, or created it knowing that it was pointless but would satisfy his boss.

  • isthisunique (unregistered)

    Some things will return undefined with their toString.

     < "undefined"

    Which is great:

     > "bob"+undefined
     < "bobundefined"

    It was probably a stupid way to check for that. Loose comparison wont do that though, contrary to intuition.


    That'll work. It's still a mystery though since when will you call a string? (You wont.)

    It's then obviously been used for any case where undefined might be converted to string likely superstitiously.

    The function should clearly be made terse:

    f => f == ""+undefined

    You can fix it so that it works properly like this:

    f => f - "" === undefined

    Or more explicitely:

    f => f.getPrevious() === undefined

    This allows you to know if you actually have the string undefined or a string with the toString of undefined, but don't tell anyone about ECMA12's dirty little secret, string unmutation (very common with ints in most languages for a long time, for example x += 4, x -= 4). I'm joking but it wouldn't surprise me if this exists somewhere or somehow.

    Thankfully this won't work:

    {toString: () => {var str = "hi";str.previous=this;return str}}
  • spaceman (unregistered) in reply to 🤷


    Protip: Try reading a book!

  • I'm not a robot (unregistered) in reply to spaceman

    Are you suggesting there's a book that 🤷 should read that explains why your links never seem to be held for moderation? Or that confirms or denies that you are Remy Porter? Both of those are awfully specific for someone to write a book about.

  • Zenith (unregistered) in reply to I'm not a robot

    I haven't done exhaustive research on it but thus far it seems like the moderation queue only applies to posts from a mobile device.

    Unsolicited commentary: for a site where we ridicule bad developers, the site has its share of WTFs.

Leave a comment on “Functional IsFunction”

Log In or post as a guest

Replying to comment #:

« Return to Article