Javascript:undefined作为函数参数 [英] Javascript: undefined as a function parameter

查看:151
本文介绍了Javascript:undefined作为函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此页面上,它显示了一些示例代码,其中包含以下行:

On this page, it shows some example code, containing the following line:

var Subject = ( function( window, undefined ) {

什么是 undefined 作为函数参数?

推荐答案

这用于防止在非严格模式下覆盖 undefined 的值。

This is used to prevent from overriding the value of undefined in non-strict mode.

在非严格模式下,可以通过为其指定其他值来覆盖 undefined 的值。

In non-strict mode, the value of undefined can be override by assigning other value to it.

undefined = true; // Or any other value

因此,使用 undefined 的值将无法按预期工作。

So, using the value of undefined will not work as expected.

严格 - 模式, undefined 是只读的,为其赋值会抛出错误。

In strict-mode, undefined is read-only and assigning value to it will throw error.

在代码中,值到最后一个参数没有传递,所以它将是隐式的sed为 undefined

In the code, the value to the last parameter is not passed, so it'll be implicitly passed as undefined.

var Subject = ( function( window, undefined ) {

}(window)); // <-- No parameter is passed for the last value

这篇关于Javascript:undefined作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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