Google ad representative line



  • We were having problems on our site where ad positions would swap content. We still haven't figured out the problem but I did find this while digging through some of Google's JavaScript: 

    function st(a) {
     return true;
    }



  • I hope they didn't forget the other Boolean functions.

    function sf(a) {
     return false;
    }

    function sfnf(a) {
      return FILE_NOT_FOUND;
    }



  • This is common in JS for callbacks.  Not a WTF. 



  • @morbiuswilters said:

    This is common in JS for callbacks.  Not a WTF. 

     

    entirely true



  • So it is not a WTF that a common JS feature, is to create a method which always return true, and still requires a parameter ?



  • @Saxov said:

    So it is not a WTF that a common JS feature, is to create a method which always return true, and still requires a parameter ?

    I have no idea how callbacks work and am just talking out of my ass.

    FTFY. 



  • @morbiuswilters said:

    @Saxov said:

    So it is not a WTF that a common JS feature, is to create a method which always return true, and still requires a parameter ?

    I have no idea how callbacks work and am just talking out of my ass.

    FTFY. 

     

    Haha well said morbiuswilters, but I think Saxov's post could also be read as"This is why google doesn't want to hire me"



  • Could you please enlighten us by illustrating a scenario where a function like

      function foo(a) { return true; }

    must be used but

      function foo2() { return true; }

    ...would not work?



  • @steamer25 said:

    Could you please enlighten us by illustrating a scenario where a function like

      function foo(a) { return true; }

    must be used but

      function foo2() { return true; }

    ...would not work?

     

     

    In many GUI frameworks, widgets can generate events of various types. To attach meaning to those events, you pass the widget a function (or object with appropriate function attached) which will be executed once the event occurs. Generally the event will have some kind of information associated with it, which will be passed in to one or more arguments in the function, and you generally need to accept that argument even if you aren't going to make use of it. The true or false return value may decide whether or not the event should stop at this handler or continue being passed up a tree of ancestor widgets. It may for various reasons be handy to have a handler that does nothing other than assert whether the chain should continue. 



  • @steamer25 said:

    Could you please enlighten us by illustrating a scenario where a function like

      function foo(a) { return true; }

    must be used but

      function foo2() { return true; }

    ...would not work?

    There is no scenario. The nature of javascript basically states that those two functions are identical, since the method body here doesn't check the arguments. That said, this was probably used as a function pointer somewhere, and the argument is there just for housekeeping.

    function fn1(a) { return a == 'zebra'; }

    function fn2(a) { return true; }

    function doStuff(fn, a) { fn(a); } where fn is fn1 or fn2

    You could make fn2() instead of fn2(a) but this will just be easier for maintainance.


Log in to reply