javatoyou 发表于 2013-1-22 22:44:36

JavaScript 中两种类型的全局对象/函数

一、核心JavaScript内置对象,即ECMAScript实现提供的不依赖于宿主环境的对象
  这些对象在程序执行之前就已经(实例化)存在了。ECMAScript称为The Global Object,分为以下几种:
  1, 值属性的全局对象(Value Properties of the Global Object)。有NaN,Infinity,undefined。
  2, 函数属性的全局对象(Function Properties of the Global Object)。有eval,parseInt,parseFloat,isNaN,isFinite,decodeURI,encodedURI,encodeURIComponent
  3,构造器(类)属性的全局对象(Constructor Properties of the Global Object)。有Object,Function,Array,String,Boolean,Number,Date,RegExp,Error,EvalError,
RangeError,ReferenceError,SyntaxError,TypeError,URIError。
  4,其它属性的全局对象(Other Properties of the Global Object),可以看出成是Java中的静态类,可以直接用类名+点号+方法名使用。有Math,JSON。
  ECMAScript规范提到这些全局对象(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 {[]: true, []: false, []: true}.
  虽然规范提到The Global Object是可以被重写的,但不会有谁去重写它们的。这里仅仅做个测试。
<div class="cnblogs_code">NaN    = 11;eval   = 22;Object = 33;Math   = 44;alert(NaN);alert(eval);alert(Object);alert(Math);
页: [1]
查看完整版本: JavaScript 中两种类型的全局对象/函数