1
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");
未顯示。如果有人可以告訴我的順序將是有益的js中的功能吊裝
這有助於。你的代碼也解釋了爲什麼'本地mymethod'被打印而不是全局打印。謝謝。 – dazzle 2013-04-25 12:38:39