mozilla
您的搜索结果

    Object

    概要

    Object 构造函数创建一个对象包装(object wrapper)。

    语法

    // Object initialiser or literal
    { [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] } 
    
     // Called as a constructor
    new Object([value])

    参数

    nameValuePair1, nameValuePair2, ... nameValuePairN
    一对对名称(字符串)与值(任何值),名称与值用冒号(colon)分隔。
    value
    任何值。

    描述

    Object 构造函数为给定的值创建一个对象包装。如果给定值是  null or undefined,将会创建并返回一个空对象,否则,将返回一个与给定值对应类型的对象。

    当以非构造函数形式被调用时,Object 等同于 new Object()

    可查看 对象初始化/字面量语法

    属性

    For properties available on Object instances, see Properties of Object instances.

    Object.length
    值为1。
    Object.prototype
    可以为所有 Object 类型的对象添加属性。

    方法

    For methods available on Object instances, see Methods of Object instances.
     
    Object.assign()
    Creates a new object by copying the values of all enumerable own properties from one or more source objects to a target object.
    Object.create()
    指定原型对象和属性来创建一个新的对象。
    Object.defineProperty()
    Adds the named property described by a given descriptor to an object.
    Object.defineProperties()
    Adds the named properties described by the given descriptors to an object.
    Object.freeze()
    Freezes an object: other code can't delete or change any properties.
    Object.getOwnPropertyDescriptor()
    Returns a property descriptor for a named property on an object.
    Object.getOwnPropertyNames()
    Returns an array containing the names of all of the given object's ownenumerable and non-enumerable properties.
    Object.getOwnPropertySymbols()
    Returns an array of all symbol properties found directly upon a given object.
    Object.getPrototypeOf()
    返回指定对象的原型对象。
    Object.is()
    Compares if two values are distinguishable (ie. the same)
    Object.isExtensible()
    Determines if extending of an object is allowed.
    Object.isFrozen()
    Determines if an object was frozen.
    Object.isSealed()
    Determines if an object is sealed.
    Object.keys()
    返回一个数组,包含指定对象的所有自有可遍历(own enumerable)属性的名称。
    Object.observe()
    Asynchronously observes changes to an object.
    Object.preventExtensions()
    Prevents any extensions of an object.
    Object.seal()
    Prevents other code from deleting properties of an object.
    Object.setPrototypeOf()
    Sets the prototype (i.e., the internal [[Prototype]] property)
    对象实例和对象原型对象

    JavaScript语言的所有对象都是由Object衍生的对象;所有对象都继承了Object.prototype的方法和属性,尽管它们可能被覆盖。例如,其它的构造器原型覆盖了constructor属性并提供了其自己的toString方法。原型对象的更改会传播给所有的对象,除非这些属性和方法在原型链中被再次覆盖。

    属性

    Object.prototype.constructor
    Specifies the function that creates an object's prototype.
    Object.prototype.__proto__
    Points to the object which was used as prototype when the object was instantiated.
    Object.prototype.__noSuchMethod__
    Allows a function to be defined that will be executed when an undefined object member is called as a method.
    Object.prototype.__count__
    Used to return the number of enumerable properties directly on a user-defined object, but has been removed.
    Object.prototype.__parent__
    Used to point to an object's context, but has been removed.

    方法

    Object.prototype.__defineGetter__()
    Associates a function with a property that, when accessed, executes that function and returns its return value.
    Object.prototype.__defineSetter__()
    Associates a function with a property that, when set, executes that function which modifies the property.
    Object.prototype.__lookupGetter__()
    Returns the function associated with the specified property by the __defineGetter__ method.
    Object.prototype.__lookupSetter__()
    Returns the function associated with the specified property by the __defineSetter__ method.
    Object.prototype.hasOwnProperty()
    Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
    Object.prototype.isPrototypeOf()
    Returns a boolean indication whether the specified object is in the prototype chain of the object this method is called upon.
    Object.prototype.propertyIsEnumerable()
    Returns a boolean indicating if the internal ECMAScript DontEnum attribute is set.
    Object.prototype.toSource()
    Returns string containing the source of an object literal representing the object that this method is called upon; you can use this value to create a new object.
    Object.prototype.toLocaleString()
    Calls toString().
    Object.prototype.toString()
    Returns a string representation of the object.
    Object.prototype.unwatch()
    Removes a watchpoint from a property of the object.
    Object.prototype.valueOf()
    Returns the primitive value of the specified object.
    Object.prototype.watch()
    Adds a watchpoint to a property of the object.
    Object.prototype.eval()
    Used to evaluate a string of JavaScript code in the context of the specified object, but has been removed.

    例子

    例子:给定 undefinednull 类型使用 Object

    下面的例子将一个空的 Object 对象存到 o 中:

    var o = new Object();
    
    var o = new Object(undefined);
    
    var o = new Object(null);
    

    例子:使用 Object 生成布尔对象

    下面的例子将Boolean 对象存到 o 中:

    // 等价于 o = new Boolean(true);
    var o = new Object(true);
    
    // 等价于 o = new Boolean(false);
    var o = new Object(Boolean());
    

    规范

    Specification Status Comment
    ECMAScript 1st Edition. Standard Initial definition. Implemented in JavaScript 1.0.
    ECMAScript 5.1 (ECMA-262)
    Object
    Standard  
    ECMAScript 6 (ECMA-262)
    Object
    Release Candidate  

    浏览器兼容性

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

    相关连接

     

    文档标签和贡献者

    此页面的贡献者有: ziyunfei, paddingme, AlexChao, iwo, teoli
    最后编辑者: ziyunfei,