【发布时间】:2013-04-19 08:18:20
【问题描述】:
function mymethod(){
alert("global mymethod");
}
function mysecondmethod(){
alert("global mysecondmethod");
}
function hoisting(){
alert(typeof mymethod);
alert(typeof mysecondmethod);
mymethod(); // local mymethod
mysecondmethod(); // TypeError: undefined is not a function
// mymethod AND the implementation get hoisted
function mymethod(){
alert("local mymethod");
}
// Only the variable mysecondmethod get's hoisted
var mysecondmethod = function() {
alert("local mysecondmethod");
};
}
hoisting();
我无法理解在这种情况下提升是如何工作的,以及为什么没有显示 alert("local mysecondmethod");。如果有人可以告诉我顺序会很有帮助
【问题讨论】:
标签: javascript hoisting