我可以调用一个函数,然后在实际运行之前覆盖变量的内容吗?覆盖另一个函数中的变量JS
所以我基本上在拉我的Git的个人资料这样的功能:
var GetGitInfo = function() {
var xhr = new XMLHttpRequest();
var gitURL = "https://api.github.com/users/myself/repos";
xhr.open("GET", gitURL);
xhr.send(null);
xhr.onreadystatechange = function() {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK) {
// console.log(xhr.responseText);
console.log(JSON.parse(xhr.responseText));
} else {
console.log('Error: ' + xhr.status);
}
}
};
}
然后我调用该函数在另一个步骤做GetGitInfo();
这一切工作正常。
但是,如果我想调用该函数并替换gitURL
变量,我将如何实现该功能?
因此,像
GetGitInfo(
gotURL= "https://api.github.com/users/new_user/repo";
);
使用的参数。 –
可能回调? – Script47
所以像'GetGitInfo([gitURL =“new_url”]);'@GerardoFurtado – PourMeSomeCode