Throughout my script I am calling the function dynamo.toolbox.add_temp_button
. An example of this is here:
if(page < total_pages){
dynamo.toolbox.add_temp_button("Next Page",function(){
dynamo.shop.enter.access(page+1,data.shop_zbid);
});
}
As you can see in this call, two parameters are passed, page+1
and data.shop_zbid
. Now these values aren't constants and change rapidly due to the overall function of the script.
Now here's the function itself:
add_temp_button : function(text,callback){
var id = text.toLowerCase().replace(/[^A-Za-z_]/g,"_");
callback = callback !== undefined && callback !== null ? callback : function(){};
var but = '<button value="'+text+'" id="jqi_state0_button'+id+'" name="jqi_state0_button'+id+'" class="dynamo_temp_button">'+text+'</button>';
$("#jqi_state0_buttonClose").before(but);
$("#jqi_state0_button"+id).bind('click',callback);
},
Do note that this has been stripped out of my script, but it is called by dynamo.toolbox.add_temp_button
.
Now, I need to know if this forms a closure, i.e will the value of the parameters I pass into the add_temp_button
function be set in stone?
My biggest worry here is the second parameter, callback
. This is a function which is passed as the callback function to $.bind
. When the bound event is triggered, will it use the current value of page
and callback
, or that which was passed initially?
Thank-you!