在javascript中提升 [英] Hoisting in javascript

查看:77
本文介绍了在javascript中提升的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我问了一个问题,有人给我一个指南,我看了它,我看到了这个

I asked a question before and somebody give me a guide and I read it and I saw this

  var temp = setTimeout,
  setTimeout = function() {};

他说由于JavaScript挂起,temp将不确定,我不明白为什么
不应该那样吗?

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() {};

为什么它未定义?

推荐答案

这是不一样的。您的多个 var 声明还声明 setTimeout

This is not the same. Your multiple var declaration also declares setTimeout:

var temp = setTimeout,
    setTimeout = function() {};

被提升至

var temp; // = undefined
var setTimeout; // = undefined
temp = setTimeout;
setTimeout = function() {};

这篇关于在javascript中提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆