JQuery\Javascript - Passing a function as a variable.
Posted
by Josh
on Stack Overflow
See other posts from Stack Overflow
or by Josh
Published on 2010-04-26T20:51:25Z
Indexed on
2010/04/26
20:53 UTC
Read the original article
Hit count: 200
jQuery
|JavaScript
I was just curious if I could pass a function as a variable. For example: I have a function
$('#validate').makeFloat({x:671,y:70,limitY:700});
I would like to do something like this:
$('#validate').makeFloat({x:function(){ return $("#tabs").offset().left+$("#tabs").width();},y:70,limitY:700});
This does not work, but ideally every time the variable was accessed it would compute the new value. So if the window was resized it would automatically adjust as opposed to a variable passed in being static. I realize I can implement this directly inside the function\widget, but I was wondering if there was some way to do something like the above.
© Stack Overflow or respective owner