如果我有一个含有多个键的对象,在其调用外部函数时,如何确定是哪个键调用了该函数?例如:
function tellYourAge() {
return function()
{
// I already know here that this refers to Population
// For example, console.log(this) will print the Population object
}
}
{
let Population = {
Mahdi: tellYourAge(),
Samuel: tellYourAge(),
Jon: tellYourAge()
};
Population.Mahdi(); // It should log 18
Population.Samuel(); // It should log 20
Population.Jon(); // It should log 21
}
Mahdi: tellYourAge('Mahdi')
。 - imvain2