Good web front-end programmer Tutorial: Objects

Good web front-end programmer Tutorial: Objects

What is an object?

Type of object is Object.

Everything is an object in JavaScript: strings, numbers, arrays, functions ...

javaScript in all things are subject

The official language to explain a little of objects:

What is the object, in fact, a type that is a reference type. It is a reference to the value of the object instance of the type. In ECMAScript reference type is a data structure for data and functions organized together. It is also often referred to as a class, but in ECMAScript has no such thing. Although ECMAScript is an object-oriented language, but do not have the basic structure of the like traditional object-oriented languages ​​supported.

How do you want to have an object?

:( create objects created in two ways)

1.New an object out;

var obj = new Object();

>>> find the target first thought is that property;                 

Add an attribute to an object;

obj.bianmei = 'wow really become beautiful'

expand:

obj.fn=function(){

     Block

}

obj.fn();

obj property may be one function;

Obj pointer in this function, the object obj point;

2. Create the object literal way:

var obj = {}

Add an attribute to an object;

Key-value pairs

obj={

     jian: zhi

}

By a key value; key of the keyboard, pressing the corresponding value will occur; this is the principle object and the same value; by key value;

Of course, such an object can be put inside the function, operation mode and functions as before, while the object of this pointer also points to the current object;

Property deleting objects

delete obj.jian;

Can write a little practice, create an object with a string concatenation of their own way, and define a method in the object, so that the pop-up method

1. your name;

2. their age;

3. own hobbies;

4. a small sum;


Guess you like

Origin blog.51cto.com/14249543/2405920