|
一、核心JavaScript內(nèi)置對(duì)象,即ECMAScript實(shí)現(xiàn)提供的不依賴(lài)于宿主環(huán)境的對(duì)象
這些對(duì)象在程序執(zhí)行之前就已經(jīng)(實(shí)例化)存在了。ECMAScript稱(chēng)為T(mén)he Global Object,分為以下幾種:
1, 值屬性的全局對(duì)象(Value Properties of the Global Object)。有NaN,Infinity,undefined。
2, 函數(shù)屬性的全局對(duì)象(Function Properties of the Global Object)。有eval,parseInt,parseFloat,isNaN,isFinite,decodeURI,encodedURI,encodeURIComponent
3,構(gòu)造器(類(lèi))屬性的全局對(duì)象(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,其它屬性的全局對(duì)象(Other Properties of the Global Object),可以看出成是Java中的靜態(tài)類(lèi),可以直接用類(lèi)名+點(diǎn)號(hào)+方法名使用。有Math,JSON。
ECMAScript規(guī)范提到這些全局對(duì)象(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是可以被重寫(xiě)的,但不會(huì)有誰(shuí)去重寫(xiě)它們的。這里僅僅做個(gè)測(cè)試。
NaN = 11;
eval = 22;
Object = 33;
Math = 44;
alert(NaN);
alert(eval);
alert(Object);
alert(Math);
it知識(shí)庫(kù):JavaScript 中兩種類(lèi)型的全局對(duì)象/函數(shù),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。