|
一、核心JavaScript內(nèi)置對象,即ECMAScript實現(xiàn)提供的不依賴于宿主環(huán)境的對象
這些對象在程序執(zhí)行之前就已經(jīng)(實例化)存在了。ECMAScript稱為The Global Object,分為以下幾種:
1, 值屬性的全局對象(Value Properties of the Global Object)。有NaN,Infinity,undefined。
2, 函數(shù)屬性的全局對象(Function Properties of the Global Object)。有eval,parseInt,parseFloat,isNaN,isFinite,decodeURI,encodedURI,encodeURIComponent
3,構(gòu)造器(類)屬性的全局對象(Constructor Properties of the Global Object)。有Object,F(xiàn)unction,Array,String,Boolean,Number,Date,RegExp,Error,EvalError,
RangeError,ReferenceError,SyntaxError,TypeError,URIError。
4,其它屬性的全局對象(Other Properties of the Global Object),可以看出成是Java中的靜態(tài)類,可以直接用類名+點號+方法名使用。有Math,JSON。
ECMAScript規(guī)范提到這些全局對象(The Global Object)是具有Writable屬性的,即Writable為true,枚舉性(Enumerable)為false,即不能用for in枚舉。ECMAScript有這么一段:
Unless otherwise specified, the standard built-in properties of the global object have attributes {[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
雖然規(guī)范提到The Global Object是可以被重寫的,但不會有誰去重寫它們的。這里僅僅做個測試。
NaN = 11;
eval = 22;
Object = 33;
Math = 44;
alert(NaN);
alert(eval);
alert(Object);
alert(Math);
it知識庫:JavaScript 中兩種類型的全局對象/函數(shù),轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。