Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  124] [ 3]  / answers: 1 / hits: 20696  / 14 Years ago, sun, january 23, 2011, 12:00:00

Here's the script:



function runScripts() {
if (arguments.length === 0) return;
chrome.tabs.executeScript(null, {
file: arguments[0]
}, function() {
arguments.shift();
runScripts.apply(null, arguments);
});
}


It doesn't work because arguments is not actually an array, it's just array-like. So how can I shift it or hack off the first element so that I can apply this function recursively?


More From » arrays

 Answers
93

I assume you want to reference the original arguments, instead of that from the callback you're passing to chrome.tabs.executeScript.



If so, you'll need to cache it first.



function runScripts() {
if (arguments.length === 0) return;
var args = [];
Array.prototype.push.apply( args, arguments );

chrome.tabs.executeScript(null, {
file: args.shift();
}, function() {
// using the modified Array based on the original arguments object
runScripts.apply(null, args);
});
}

[#94092] Thursday, January 20, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;