如何给undefined赋值

How to assign value to undefined

Todd 在 his article 中提到可以分配未定义的值(作为将对象放入参数而不分配它的原因):

In ECMAScript 3, undefined is mutable. Which means its value could be reassigned, something like undefined = true; for instance, oh my! Thankfully in ECMAScript 5 strict mode ('use strict';) the parser will throw an error telling you you’re an idiot. Before this, we started protecting our IIFE’s by doing this:

(function (window, document, undefined) {

})(window, document);

Which means if someone came along and did this, we’d be okay:

undefined = true;
(function (window, document, undefined) {
    // undefined is a local undefined variable
})(window, document);

然而,我试图分配它但没有任何运气:

$ undefined = true
$ true
$ undefined
$ undefined

谁能说说怎么做?只是出于好奇。或者新的浏览器不再允许这样做?

回答:

(function(undefined){

    console.log("\"undefined\" parameter:", undefined);

})("test");

它会起作用。