Function callFunction(function)



  • I created a simple website with Macromedia Dreamweaver 8 and just for the fun of it (oh well...) I looked through the code it generated. I was a bit surprised when I found the onClick property of my "Close window" button, and found this:

    MM_callJS('window.close()');

    instead of this:

    window.close(); 

    Ok, a bit unexpected, but sure there's gotta be a reason for it. Maybe some advanced error checking? I went through the code again, and found the function:

    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    }

    Version 2.0, you say? Wow! That makes it so much more useful! I guess they ran out of new feutures...



  • Version 1 was:

    var MM_callJS = eval;

     

     However, the topic is not THAT useless. In fteqcc, this code generates broken output:

    (SomeFunction())(arg); 

     and this works:

    void callFunction(void() func, float arg) { func(arg); }

    callFunction(SomeFunction, arg);



  • But instead of:

    callFunction(SomeFunction, arg);

    can't you just write:

    SomeFunction(arg);



  • Not necessarily, if the SomeFunction pointer-to-function is a variable that you get from somewhere else.  (Or maybe there is some much simpler way to call a pointer-to-function's target - I dunno, I'm not a JS guy.)

     



  • DW still contains crap JS like that?

    Dude. 



  • @emurphy said:

    Not necessarily, if the SomeFunction pointer-to-function is a variable that you get from somewhere else.  (Or maybe there is some much simpler way to call a pointer-to-function's target - I dunno, I'm not a JS guy.)

     

    Ok, now I get your point. For example, a user could enter a function name in a text input box and execute it. But still, applying it to "window.close()" is pretty damn stupid.



  • @emurphy said:

    Not necessarily, if the SomeFunction pointer-to-function is a variable that you get from somewhere else.  (Or maybe there is some much simpler way to call a pointer-to-function's target - I dunno, I'm not a JS guy.)

     

    var x = function(){ alert("foo"); }; 
    x();
    


  • var x = 'MM_callJS(x+x);';

    MM_callJS(x);

    //muhahaha...!
     


Log in to reply
 

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