想请问版上各位大神以下的code:
function getData(name, callback){
setTimeout(() => {
callback({ name: name, age: Math.floor(Math.random()*10)});
}, 2000);
}
function getMovies(age, callback) {
if (age < 12) {
setTimeout(() => {
callback("cartoon movies");
}, 1500);
} else if (age < 18) {
setTimeout(() => {
callback("teen movies");
},1500);
} else {
setTimeout(() => {
callback("adult movies");
}, 1500);
}
}
上方function declaration之中的
callback({ name: name, age: Math.floor(Math.random()*10)});
是什么样的表述方法呢?
看起来像
let callback = {name: name, age: Math.floor(Math.random()*10)}; 但没有let跟=且多了();
又像是单纯的array object,如{name: name, age: Math.floor(Math.random()*10)};但前面却多了一个callback()
把他包起来?
难道callback放在{name: name, age: Math.floor(Math.random()*10)};前面就只是要与上方的参数对照吗?
感谢各位大大解惑!