I have the following:
var doHandler = function (link, form, close) {
var $form = form;
var $link = link;
var dialogTitle = $form.find("#Title").val();
// some code
}
I’d like to change this to:
function doTask(??) {
var dialogTitle = $form.find("#Title").val();
// some code
}
var doHandler = function (link, form, close) {
var $form = form;
var $link = link;
doTask(??)
}
Can someone explain:
- what “var $form = form;” is doing
- what parameter I should pass to doTask $form or form?
- should that first line in doTask reference $form or form
- do I need to declare the function before calling if it is in the same file?
Sorry but it’s really confusing what is the difference and why the $ is there
The character
$can be used in a variable name just like any other of the valid characters, and a variable name containing a$has no special meaning in the language.As the variables for the form and the link are local variables, you have to pass them on to the function to use them.
A function doesn’t have to be defined above the code that uses it, as long as it’s in the same (or previous) file or the same (or previous) script block.
In the
doTaskfunction you use neither the variableformnor the variable$form, as they are both local to thedoHandlerfunction. You use the parameter that is sent to the function. This parameter could also be namedformor$form, but it could also be named something completely different.It seems pointless to copy the parameters
linkandformto the local variables$linkand$form, though. You could just as well use the parameters: