Callbacks? Don't want to wait for code to execute
Hello all
I am running a regular expression replace on an array (iterating through each index in the array), and pushing matches in to a new array. The code sometimes takes a second to execute, as the array it is running against is about 800 long.
I want to be able to run this code without having the browser lock up. I heard that there is some way to let the code execute without locking up the browser by using callback logic? I heard that this is similar to how Node is programmed.
Please could someone let me know how I would go about this?
My current code looks like this:
Code:
$("form[name=filefinder] input[name=s]").keyup( function(){
if(!s_cache[this.value]){
var regexp = new RegExp(this.value, "gi");
var list = files.split(/\n/g);
var result = [];
for(var i in list){
if(!!list[i].match(regexp)){
result.push(list[i].replace(regexp, "<span class=\"highlight\">"+this.value+"</span>"));
}
}
s_cache[this.value] = result;
}
update_filefinder_list(s_cache[this.value]);
});