Tag: Indicates select Alert No application developed his field obj
An overview of JavaScript objects
What is an object is, in fact, a type, that is, a reference type. The value of the object is an instance of the reference type.
A reference type in JavaScript is a data structure that organizes data and functionality together. It is also often called a class, but there is no such thing in JavaScript (impersonation).
Although JavaScript is an object-oriented language, it does not have the basic structure of classes and interfaces supported by traditional object-oriented languages.
It is an ideal choice for storing and transferring data in an application.
How to create a JavaScript object-Create an object using the new operator
functionObjrun () {return' 123 ';}varbox =NewObject ();//An object was createdAlerttypeofbox);//object type is objects //Create an attribute field for an objectBox.name = ' Li Tinghui '; Box.age= 28; Box.run=Objrun (); Alert ("My name is" +box.name+ ", I Am" +box.age+ "year old ...");//Get property fields for an objectalert (Box.run);//calling methods in an object
The new keyword can be omitted
var // The New keyword is omitted = ' Huang Jia ai '= A,alert ("My name is" +box.name+ ", I this year" +box.age+ "years old ...");
How JavaScript objects are created-using literal notation
var box = { // create attribute field age:28, function// The method in the object return ' run '; }; Alert ("My name is" +box.name+ ", I Am" +box.age+ "year old ..."); Alert (Box.run ()); // calling methods in an object
Property fields can also be used as String forms
var box = { // create attribute field ' age ':};alert ("My name is" +box.name+ ", I'm this year" +box.age+ "years old .....");
Create objects by using literal methods, but you can use the traditional way when creating fields for objects
var box = {}; // literal method declares an empty object // traditional way to create field properties for an object box.age =; // There are two ways to output a property // dot notation output alert ("My name is" +box[' name ']+ ", I am this year" +box[' age ']+ "years old ..."); // bracket notation Output, note the need to enclose the quotation marks
How JavaScript objects are created-display constructors to create objects
Whenever a function is used by the new operator, the function can become a constructor
var function () { this. Name = "O2"; } var New M (); alert (o2.name);
How to create a JavaScript object-object.create ()
var p = { name:"O3"}; var o3 = object.create (p) alert (o3.name);
Passing an object as a parameter to a function
In the actual development process, we generally prefer the literal declaration method. Because it is clear, the syntax code is few, but also gives the person a kind of encapsulation feeling. Literals are also the preferred way to pass a large number of optional parameters to a function.
function // parameter is an object if (obj.name!=// determines if the attribute exists if (obj.age! = undefined) alert (obj.age); } var obj=' Li Tinghui ' , Box (obj);
Delete Object properties Using Delete
var box == ' Orient card '; } alert (Box.name); Delete box.name; alert (box.name); // has been deleted, undefined
A detailed description of JavaScript objects