问题
I asked a question before and somebody give me a guide and I read it and I saw this
var temp = setTimeout,
setTimeout = function() {};
He said that temp will be undefined due to JavaScript hoisting and I dont understand why Its not should be like that?
var temp;
temp = setTimeout;
setTimeout = function() {};
so why its undefined?
回答1:
This is not the same. Your multiple var declaration also declares setTimeout
:
var temp = setTimeout,
setTimeout = function() {};
which is hoisted to
var temp; // = undefined
var setTimeout; // = undefined
temp = setTimeout;
setTimeout = function() {};
来源:https://stackoverflow.com/questions/13505048/hoisting-in-javascript