Chapter V web front-end development engineer --JavaScript Advanced Programming 5-5 JavaScript object manipulation

                                                                           JavaScript object manipulation

 

This lesson is to talk:

  1. JavaScript object creation
  2. JavaScript Object basic operations
  3. JavaScript function object

                                                                          Speaker teachers: Head teacher

Two. JavaScript Object basic operations

1.  traversing members

for(sx in p){

console.log(sx);

console.log(p[sx]);

}

// attributes are unordered

Object.keys(p) ;

Returns an array of sort.

2. The  members of the traversal View

Object .hasOwnProperty ( "attribute name")   if it returns true itself, if it is inherited return false

3. Delete members

delete p.name

4. Members of the learning characteristics

Object.getOwnPropertyDescriptor (Object, "property name")   characteristics or properties of the object was

1.configurable, whether the property is configurable. Meaning Configurable include: whether the property can be deleted (delete), whether or not you can modify the properties of the writable, enumerable, configurable attribute.

2.enumerable, property is enumerable. Enumerable meanings include: Is it possible to traverse through for ... in, is it possible method to obtain property by name Object.keys ().

3.writable, whether the property can be rewritten. Rewritable meanings include: whether the property can be re-assigned.

4.value, the default value of the property.

5.set, Rewriter property (for the time being so called). Once the property is re-assigned, this method is called automatically.

6.get, reader attributes (for the time being so called). Once the property is accessed read, this method is called automatically.

5. The  the Constructor  Constructor

A built-in property belonging to the object, to point to create this object constructor

Statement of the nature of the object is no different in two ways

There  o = {};

var o1 = new Object{};

a.  Constructor === O1.  constructor ;

number. Constructor

function f(){}

f. Constructor

function. Constructor

1. Constructor

V R = 1;

to.  constructor ;

6. Type checking

typeo of operator

Returns a string representation, indicates what type it is

such as:

typeof "a" returns the string 

typeof null returns an object. This is a mistake javascript language itself, in order to be compatible has been no change, it should return null son.

typeof undefined返回undefined

instanceof  instance of a constructor

o instanceof object

o instanceof o. Constructor

8. constructor to create objects using

Var o = {name:“abc”};

V would O1 = a.  Constructor

O 1.name // o1 create a new object, rather than copying the o.

 

Guess you like

Origin blog.csdn.net/wgf5845201314/article/details/92380783