调用一个函数两次

calling a function twice

本文关键字:两次 函数 一个 调用      更新时间:2023-09-26

我正在尝试调用一个函数两次,但是使用当前代码,我跳过了getPoints()函数,并调用了setInterval中的getPoints()函数。我正在尝试让它调用getPoints()函数,然后调用setInterval中的函数。

var background;
// background page
background = chrome.extension.getBackgroundPage();
// get totals
getPoints(background.localStorage.points);
// update every 30 seconds
setInterval(function() {
  console.log("func");
  getPoints(background.localStorage.points);
}, 30000);

试试这个:

window.onload = function() {
    var background;
    // background page
    background = chrome.extension.getBackgroundPage();
    // get totals
    getPoints(background.localStorage.points);
    // update every 30 seconds
    setInterval(function () {
        console.log("func");
        getPoints(background.localStorage.points);
    }, 30000);
};