Hi,
I'm developing an extension. What I'm trying to do is to avoid
callback-style calls for chrome.tabs, etc.
Here is the code I wrote to accomplish that
function avoid_callback(what, func, args) {
var x, callback = function (y) {x = y;};
if (!args || !args.length)
args = new Array();
args.push(callback);
what[func].apply(what, args);
return x;
}
Then the call would be
var tabs = avoid_callback(chrome.tabs, "getAllInWindow", windowId);
For some reason I get tabs _undefined_.
The avoid_callback function was tested in Firefox, the exact code used
is
var obj = { f: function(x, c) { c(x); } };
alert(avoid_callback(obj, "f", [1])); // this shows 1
I can't figure out why it doesn't work for chrome.tabs.
Another question: maybe there is a way for elegant callback use which
I'm not aware of? In general, I'm trying to avoid the code like
// find id of the current window
var win_id = null;
chrome.windows.getCurrent(function (win) {
win_id = win.id;
});
this.win_id = win_id;
Thanks,
Denis
PS. Google Chrome 3.0.182.3 32 bit for Windows running on Ubuntu 8.04
with Wine 1.1.22
--~--~---------~--~----~------------~-------~--~----~
Chromium Discussion mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-discuss
-~----------~----~----~----~------~----~------~--~---