javascript函数声明提前的一个例子
来源:互联网 发布:tensorflow 安装 编辑:程序博客网 时间:2024/06/10 02:34
Notice that the assignment portion of the declarations were not hoisted.Only the name is hoisted. This is not the case with function declarations,where the entire function body will be hoisted as well. But remember that thereare two normal ways to declare functions. Consider the following JavaScript:
function test() {
foo(); //TypeError "foo is not a function"
bar(); //"this will run!"
var foo =function () { // function expression assigned to local variable 'foo'
alert("thiswon't run!");
}
functionbar() { // function declaration, given the name 'bar'
alert("thiswill run!");
}
}
test();
In this case, only the function declaration has its body hoisted to thetop. The name ‘foo’ is hoisted, but the body is left behind, to be assignedduring execution.
That covers the basics of hoisting, which is not as complex or confusingas it seems. Of course, this being JavaScript, there is a little morecomplexity in certain special cases.
- javascript函数声明提前的一个例子
- JavaScript的声明提前
- JavaScript 中对变量和函数声明提前的示例
- JavaScript 函数和变量声明的"提前"(hoist)行为
- JavaScript中对变量和函数声明的提前
- javascript的函数作用域及声明提前
- JavaScript 中对变量和函数声明的“提前”
- javascript小记——变量和函数的声明提前
- JavaScript 中对变量和函数声明的“提前”
- JavaScript函数作用于之声明提前
- JavaScript函数作用域和声明提前
- 一个简单的javascript小程序学习javascript作用域和局部变量提前声明
- javascript 声明提前
- JavaScript提前声明
- JavaScript 变量声明提前
- javascript 声明提前
- JavaScript声明提前
- javascript变声声明提前
- 关于win8下pip安装mysql找不到config-win.h文件的一种解决方案
- git add和git commit
- 今日学一招:关于JavaScript为何要限制跨域访问
- OC入门第一课
- Python程序执行原理+
- javascript函数声明提前的一个例子
- iOS的事件分发
- Object-C第一课,我们要注意到的小细节
- 怎么创建一个设备
- c语言 格式化文件输入输出
- POJ - 1061 青蛙的约会
- STL源码剖析---空间配置器
- 回文素数的打印
- English in March