Javascript Object objects learn notes

  • 2020-05-05 10:56:19
  • OfStack

new Object ()

new Object(value)

parameters value
An optional parameter that declares the original value (that is, a number, Boolean, or string) to be converted to an Number object, an Boolean object, or an String object. Prior versions of JavaScript 1.1 and ECMAScript Vl do not support this object.

returns the value

If no value argument is passed to the constructor, it will return a newly created Object instance. If the original value parameter is specified, the constructor creates and returns a wrapper object with the original value, the Number object, Boolean object, or String object. When the Object() constructor is called as a function without the new operator, it behaves the same as when the new operator is used.

A reference to an JavaScript function, which is the constructor of the object


1.hasOwnProperty( )
Checks if the object has locally defined (non-inherited) properties with a specific name.

    <script type="text/javascript">
            var o = new Object();
            alert(o.hasOwnProperty("name"));    //true
            alert(o.hasOwnProperty("age"));    //false



Any object.

returns the value
If object is a prototype of O, true is returned. false is returned if o is not an object or object is not the original type of o.

The JavaScript object inherits the properties of the prototype object. The prototype of an object is referenced by the prototype attribute used to create and initialize the constructor of the object. The isPrototypeOf() method provides a way to determine whether an object is a prototype of another object. This method can be used to determine the class of the object.


var o = new Object(  );                          // Create an object
Object.prototype.isPrototypeOf(o)                // true: o It's an object
Function.prototype.isPrototypeOf(o.toString);    // true: toString It's a function
Array.prototype.isPrototypeOf([1,2,3]);          // true: [1,2,3] It's an array
// Here is another way to perform the same test
(o.constructor == Object);  // true: o was created with Object(  ) constructor
(o.toString.constructor == Function);  // true: o.toString is a function
/ The prototype is the object itself. The following call returns true
// Declarative function continuation Function.prototype and Object.prototyp attribute .



A string containing the name of the object prototype.

The return value
object returns true if object has a non-inherited property named propname and that property is enumerable (it can be enumerated with the for/in loop).

The for/in statement lets you iterate over the enumerable properties of an object. But not all properties of an object are enumerable. Properties added to an object by JavaScript code are enumerable, while predefined properties (such as methods) of internal objects are generally not enumerable. The propertylsEnumerable() method provides a way to distinguish enumerable from unenumerable properties. Note, however, that the ECMAScript standard states that the propertyIsEnumerable() method does not detect the stereotype chain, meaning that it applies only to local properties of an object and cannot detect the enumerability of inherited properties.


var o = new Object(  );                // Create an object
o.x = 3.14;                            // Define a property
o.propertyIsEnumerable("x");           // true attribute x Is local and enumerable
o.propertyIsEnumerable("y");           //false : o There is no attribute y
o.propertyIsEnumerable("toString");    //false : toStrlng Properties are inherited
Object.prototype.propertyIsEnumerable("toString");  // false: The enumeration of


When the standard restricts the propertylsEnumerable() method to detecting only non-inherited properties, it is clearly wrong. Internet Explorer 5.5 implements this approach as a standard. The propertyIsEnumerable() approach implemented by Nestacpe 6.0 takes into account the prototype chain. While this approach is desirable, it conflicts with the standard, so Netscape 6.1 has modified it to match IE 5.5. Because of this error in the standard, this method is not very useful.

 var obj = new Object();
     obj.title = 'aaa';
     obj.funb = function(a, b)

Here is one method,

<script language="javascript">
function object(value,a,b){
        this.title = value;
        this.funb = function(){
                      this.a = a;
                      this.b = b;
   var obj = new object("aaa",1,2);
// Here you add a new method to the object = "123456";

This is another way to do

Related articles: