Does what it says on the tin



  • Can't say that this function I just came across isn't well described:

     

    function JustReturnFalse {

    return false;

    }

     

    As to why it exists, I don't dare to delve deeper to find out. 



  • @valerion said:

    Can't say that this function I just came across isn't well described:

     

    function JustReturnFalse {

    return false;

    }

     

    As to why it exists, I don't dare to delve deeper to find out. 

    I'm guessing for the same reason most of these exist. There used to be some logging there, but it's gone. 


  • Discourse touched me in a no-no place

    Units tests exist somewhere, and a pointer to this function is used to test one of the tests?

    Optimistic, granted, but possible. 



  • Probably to do with event juggling. Stick this one in an event to return false from it.



  • @dhromed said:

    Probably to do with event juggling. Stick this one in an event to return false from it.

    That's my guess too. Somewhere in the code, you have to supply a callback function that returns boolean, otherwise it complains. This is a dummy function to satisfy the requirement. It could also be a neater alternative to "if (function was supplied) then (my_bool = result of calling the function) else (my_bool = false)".



  • Strangely enough, I came across the exact same code snipplet in JavaScript the other day. Forgot what site it was on, though.



  • @phelyan said:

    @valerion said:

    Can't say that this function I just came across isn't well described:

     

    function JustReturnFalse {

    return false;

    }

     

    As to why it exists, I don't dare to delve deeper to find out. 

    I'm guessing for the same reason most of these exist. There used to be some logging there, but it's gone. 

    I don't know -- I think the 'Just' in the function name means 'only.'  So I doubt it ever did anything else.
     



  • I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.



  • @valerion said:

    Can't say that this function I just came across isn't well described:

     

    function JustReturnFalse {

    return false;

    }

     

    As to why it exists, I don't dare to delve deeper to find out. 

    Aren't there some missing parentheses?



  • @Volmarias said:

    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };
    


  • @Lingerance said:

    @Volmarias said:
    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };

    There are some rather annoying subtleties with how JavaScript handles closures that, in certain special cases, would cause a "quasi memory leak" if it was done your way, but not if it was done in the original way. So maybe the guy knew of them and tried to avoid them. But then again, you'd at least want to put some comments in there in such a case. So my money is on run-off-the-mill dumbness.




  • @FraGag said:

    @valerion said:

    Can't say that this function I just came across isn't well described:

     

    function JustReturnFalse {

    return false;

    }

     

    As to why it exists, I don't dare to delve deeper to find out. 

    Aren't there some missing parentheses?

     

    I didn't copy n' paste, I typed... you get the idea though.

    If I've got time later I'll search the code to see where it's being called from. Perhaps there will be a perfectly rational explanation for it. 



  • @PSWorx said:

    @Lingerance said:
    @Volmarias said:
    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };

    There are some rather annoying subtleties with how JavaScript handles closures that, in certain special cases, would cause a "quasi memory leak" if it was done your way, but not if it was done in the original way. So maybe the guy knew of them and tried to avoid them. But then again, you'd at least want to put some comments in there in such a case. So my money is on run-off-the-mill dumbness.


    I'm not really sure what dumbness there is. It's a function, that returns false. This is useful for above-mentioned reasons in overriding default behaviors, or just passing a function that returns false for whatever reason you might need it (and there are indeed valid reasons for passing function pointers in JavaScript). Unless there's code such as "function doStuff() { if(true) foo; else if (false) bar; else if (filenotfound) return JustReturnFalse(); }" I'm not inclined to call this much of a WTF as much as simply poor naming conventions. The Real WTF is that we're all still discussing this.



  • @Volmarias said:

    (and there are indeed valid reasons for passing function objects in JavaScript)

    Fixed. There's no such thing as a pointer in JavaScript (at least, not in the implementations I've seen).



  • @Volmarias said:

    @PSWorx said:
    @Lingerance said:
    @Volmarias said:
    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };

    There are some rather annoying subtleties with how JavaScript handles closures that, in certain special cases, would cause a "quasi memory leak" if it was done your way, but not if it was done in the original way. So maybe the guy knew of them and tried to avoid them. But then again, you'd at least want to put some comments in there in such a case. So my money is on run-off-the-mill dumbness.


    I'm not really sure what dumbness there is. It's a function, that returns false. This is useful for above-mentioned reasons in overriding default behaviors, or just passing a function that returns false for whatever reason you might need it (and there are indeed valid reasons for passing function pointers in JavaScript). Unless there's code such as "function doStuff() { if(true) foo; else if (false) bar; else if (filenotfound) return JustReturnFalse(); }" I'm not inclined to call this much of a WTF as much as simply poor naming conventions. The Real WTF is that we're all still discussing this.

    I am far from condemning first class functions and anonymous function expressions in JS, lord knows. They two of the best features of the language. I agree, dumbness was a bit too strong of a word. But it was still enough to make a co-worker post it here, so there obviously are issues. So, yeah, he should at least have named it along the lines of "GenericCallbackDummy" or somesuch to make it clear what's it for.
     



  • @Lingerance said:

    @Volmarias said:
    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };

    var foo = function () { stuff; }

    is entirely indistinguishable from

    function foo() { stuff; }


  • @dhromed said:

    @Lingerance said:
    @Volmarias said:
    I'm assuming that this is JavaScript. Usually, if you return false from something, you can modify some built in behavior. All of those "right click protection" scripts that you run across are basically document.oncontextmenu = returnFalseFunction;. This is just a funny name.

    Which prompts the question why not have an inline function for that?

    //Not tested, probably has syntax errors.
    var functionPointer = function { return false; };

    var foo = function () { stuff; }

    is entirely indistinguishable from

    function foo() { stuff; }

    Point was to not put it as var foo = function () {}, but put it on the part that needs the call back. If it's in a onevent then:

    <a OnClick="return false" href="#">Click me!</a>
    

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.