考虑以下示例:
var company = 'Apple',
log = console.log;
function f1() {
log(company);
var company = 'Twilio';
log(company)
}
function f2() {
log(company());
function company() {
return 'Zynga';
}
}
function f3() {
log(company());
var company = function() { return 'RIM'; };
}
log(company);
log('---');
f1();
log('---');
f2();
log('---');
f3();
萤火虫的输出是:
"Apple"
---
undefined
"Twilio"
---
"Zynga"
---
TypeError: company is not a function
那么为什么f3
在其他人工作正常的情况下提升给我错误呢?