欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript高級程序設(shè)計(jì) 讀書筆記之十一 內(nèi)置對象Global

 更新時(shí)間:2012年03月07日 07:55:17   作者:  
由ECMAScript實(shí)現(xiàn)提供的、獨(dú)立于宿主環(huán)境的所有對象,在ECMAScript程序開始執(zhí)行時(shí)出現(xiàn)
內(nèi)置對象
  定義:由ECMAScript實(shí)現(xiàn)提供的、獨(dú)立于宿主環(huán)境的所有對象,在ECMAScript程序開始執(zhí)行時(shí)出現(xiàn)。

  由定義可知開發(fā)者不必明確實(shí)例化內(nèi)置對象,它已被實(shí)例化了。在ECMAScript-262只定義了兩個(gè)內(nèi)置對象,即Global和Math

Global
  Global對象是ECMAScript中最特別的對象,因?yàn)閷?shí)際上它根本不存在。

  由于在ECMAScript中不存在獨(dú)立的對象,所有函數(shù)都必須是某個(gè)對象的方法,如前面提到的isNaN()、isFinite()、parseInt()和parseFloat()等,都是Global對象的方法。

  escape()、encodeURI()、encodeURIComponent()、unescape()、decodeURI()、decodeURIComponent()、eval()等都是Global的方法。

escape() && encodeURI() && encodeURIComponent()
  這幾個(gè)方法用于對字符串進(jìn)行編碼。

  escape不編碼字符有69個(gè):*,+,-,.,/,@,_,0-9,a-z,A-Z

  encodeURI不編碼字符有82個(gè):!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z

  encodeURIComponent不編碼字符有71個(gè):!, ',(,),*,-,.,_,~,0-9,a-z,A-Z

  escape():不建議用,已淘汰

  encodeURI():對URL進(jìn)行編碼,示例:
復(fù)制代碼 代碼如下:

encodeURI("http://www.dbjr.com.cn/a file with spaces.html")
// outputs http://www.dbjr.com.cn/a%20file%20with%20spaces.html

encodeURIComponent():對參數(shù)進(jìn)行編碼,示例:
復(fù)制代碼 代碼如下:

param1 = encodeURIComponent("http://xyz.com/?a=12&b=55")
url ="http://domain.com/?param1="+ param1 +"&param2=99";
// outputs http://www.domain.com/?param1=http%3A%2F%2Fxyz.com%2F%Ffa%3D12%26b%3D55&param2=99

unescape() && decodeURI() && decodeURIComponent()
  這幾個(gè)方法用于對字符串進(jìn)行解碼。

eval()
  eval()可能是ECMAScript語言中最強(qiáng)大的方法,該方法就像整個(gè)JavaScript的解釋程序,接受一個(gè)參數(shù),即要執(zhí)行的ECMAScript(或JavaScript)字符串。

  示例:

復(fù)制代碼 代碼如下:

var msg="Hello world";
eval("alert(msg)");//alert "Hello world"

注意,eval()功能很強(qiáng)大,但也很危險(xiǎn),特別在用eval執(zhí)行用戶輸入的內(nèi)容時(shí),可能會被代碼注入。

Global對象的所有屬性
  Global不只有方法,它還有屬性,Global對象的所有屬性:

屬性

說明

undefined

Undifined類型的字面量

NaN

非數(shù)的專用數(shù)值

Infinity

無窮大值的專用數(shù)值

Object

Object的構(gòu)造函數(shù)

Array

Array 的構(gòu)造函數(shù)

Function

Function 的構(gòu)造函數(shù)

Boolean

Boolean 的構(gòu)造函數(shù)

String

String 的構(gòu)造函數(shù)

Number

Number 的構(gòu)造函數(shù)

Date

Date 的構(gòu)造函數(shù)

RegExp

RegExp 的構(gòu)造函數(shù)

Error

Error 的構(gòu)造函數(shù)

EvalError

EvalError 的構(gòu)造函數(shù)

RangeError

RangeError 的構(gòu)造函數(shù)

ReferenceError

ReferenceError 的構(gòu)造函數(shù)

SyntaxError

SyntaxError 的構(gòu)造函數(shù)

TypeError

TypeError 的構(gòu)造函數(shù)

URIError

URIError 的構(gòu)造函數(shù)

作者:天行健,自強(qiáng)不息

出處:http://artwl.cnblogs.com

相關(guān)文章

最新評論