以下は、Chrome拡張機能の開始ページのスニペットです。 https://developer.chrome.com/extensions/getstartedここで、callback()の定義は何ですか?
最後に呼び出されるcallback()関数の本体がどこにあるのでしょうか。
/**
6 * Get the current URL.
7 *
8 * @param {function(string)} callback - called when the URL of the current tab
9 * is found.
10 */
11 function getCurrentTabUrl(callback) {
12 // Query filter to be passed to chrome.tabs.query - see
13 // https://developer.chrome.com/extensions/tabs#method-query
14 var queryInfo = {
15 active: true,
16 currentWindow: true
17 };
18
19 chrome.tabs.query(queryInfo, function(tabs) {
20 // chrome.tabs.query invokes the callback with a list of tabs that match the
21 // query. When the popup is opened, there is certainly a window and at least
22 // one tab, so we can safely assume that |tabs| is a non-empty array.
23 // A window can only have one active tab at a time, so the array consists of
24 // exactly one tab.
25 var tab = tabs[0];
26
27 // A tab is a plain object that provides information about the tab.
28 // See https://developer.chrome.com/extensions/tabs#type-Tab
29 var url = tab.url;
30
31 // tab.url is only available if the "activeTab" permission is declared.
32 // If you want to see the URL of other tabs (e.g. after removing active:true
33 // from |queryInfo|), then the "tabs" permission is required to see their
34 // "url" properties.
35 console.assert(typeof url == 'string', 'tab.url should be a string');
36
37 callback(url);
38 });
39
コールバック関数は、 'getCurrentTabUrl'関数のパラメータとして提供されます。だから、何でもかまいません。 – Erazihel