これは、コールバックを提供していないためです。
function doSomethingLater(callback) {
setTimeout(callback, 1000);
}
console.log('This is before the callback');
doSomethingLater(function() {
console.log('This is the callback')
});
ですから、あなたがコールバック関数に渡されていないvar gaiaId = getGaia();
を呼び出しているとき
[編集]これはあなたのコードは次のように見える必要があるだろうかです:
function getGaia(callback) {
chrome.identity.getProfileUserInfo(function(userInfo){
var userId = userInfo.id;
// This will call the function that you pass in below
//and pass in userInfo.if as a parameter
callback(userInfo.id);
});
}
var gaiaId = getGaia(function (id) {
// id === userInfo.id from above
// Do something with the id that you pass in
});
関数をJavaScriptの変数のように考えることができます。
ですから、このような関数を変数に割り当てることができます。
var foo = function() { ... }
これは、あなたが通常の変数のような関数にこれを渡すことができることを意味します。あなたがパラメータとして関数を渡すとき、あなたはパラメータで指定した名前に機能を割り当てる:
var foo = function() { ... }
function hasCallback(callback) {
// The following two line do exactly the same thing:
callback(); // Using the function that you passed in
foo(); // Using the function directly
}
hasCallback(foo);
私は上記の行っているすべては、私はちょうど機能を作成した代わりに、変数foo
を作成するのであり、インライン:
var foo = function() { ... }
function hasCallback(callback) {
// The following two line do exactly the same thing:
callback(); // Using the function that you passed in
foo(); // Using the function directly
}
hasCallback(foo);
// Becomes:
function hasCallback(callback) {
callback(); // Using the function that you passed in
}
hasCallback(function() { ... });
あなたは 'callback'または' Callback'を使用していますか?エラーは、あなたが "コールバック"を大文字にしていると言います。しかし、あなたのコードは小文字としてコールバックしています。 – zero298
'Callback'は関数ではありません。ここでCはコールバックの大文字です –
編集が行われました - タイプミスでした – JamesJameson2456