JavaEye javascript object-oriented technology foundation (1)

Transfer from:

Director: sdcyst Read: 27133 times Comments: 80 Update Time :2008-12-15
Introduction javascript read a lot of object-oriented technology, the article is very faint. Why? Not because of poorly written, but too esoteric.
javascript objects not explain how matter, a straight up on the subject, classes / inheritance / prototype / private variables ....
The result, seen most of the day, with a general understanding of, and makes an aftertaste, as if nothing to understand ...
This article is for reference <<javascript-the definitive guide,5th edition>> Chapter 7,8,9 s and written, and I will try according to the original structure of the book to illustrate the javascript object-oriented technology (Object / Array - "Functions -" Class / constructor / prototype). For some of my Insincere and are not allowed to place myself, I will attach the original English sentences, for your reference.
If we did not show that the text appears all the English sentences (except for program body) are quoted from <<javascript-the definitive guide,5th edition>>.

Objects and arrays (Objects and Arrays)
What is the object? To a number of "name - Property," a combination of a unit on the inside, on the formation of an object. We can be interpreted as javascript objects is that some "key - value" pairs (An object is a collection of named values. These named values are usually referred
to as properties of the object .-- Section3.5).
"Name" can only be a string type, can not be other types, but the type attribute is arbitrary (digital / string / other objects ..). Can use new Object () to create an empty object, you can simply use "()" to create an empty object, which is equivalent to the role of the two.

var emptyObject1 = {};           // Creates an empty object  
var emptyObject2 = new Object(); // Creates an empty object  
var person = {"name":"sdcyst",   
          "sex":"male"};     // Creating a person object that contains the initial value of  
alert(;              //sdcyst   
alert(person["age"]);            //18 

From the above examples we can see that access to an object's properties, you can simply use the object name plus "." Added the name attribute, you can also use "[]" operator to obtain, this time in [] inside the The property name should be in quotes, because the index is a string object type.
javasript object is a variable number of attributes in the creation of an object at any time after any of the attributes assigned to it.

var person = {}; = "sdcyst";   
person["age"] = 18;   
alert( + "__" + person.age); //sdcyst__18   
var _person = {name:"balala","age":23}; // In constructing an object  , Property names do not have to quote to dimension  (name),   
                    // But still is a string type  . When in access  [] Still need quotation marks within the  
alert(_person["name"] + "__" + person.age); //balala__23   
alert(_person[name]);                   //undefinied 

Through "." Operator to obtain the properties of an object, you must have to know the property name. Generally speaking, "[]" operator to obtain the object properties of a number of more powerful,
In the [] to put some expressions to get the property value,
For example can be used in loop control statements, while "." Operators do not have this flexibility.
var name = {"name1":"NAME1","name2":"NAME2","name3":"NAME3","name4":"NAME4"};   
var namestring = "";   
for(var props in name) {  // Circular name properties in an object name  
    namestring += name[props];   
alert(namestring);  //NAME1NAME2NAME3NAME4   
namestring = "";   
for(var i=0; i<4; i++) {   
    namestring += name["name"+(i+1)];   
alert(namestring);  //NAME1NAME2NAME3NAME4  

delete operator to delete an object in an attribute to determine whether there is an attribute can be used "in" operator.

var name = {"name1":"NAME1","name2":"NAME2","name3":"NAME3","name4":"NAME4"};   
var namestring = "";   
for(var props in name) {  // Circular name properties in an object name  
    namestring += name[props];   
alert(namestring);  //NAME1NAME2NAME3NAME4   
delete name.name1;  // Delete name1 property  
delete name["name3"];  // Delete name3 property  
namestring = "";   
for(var props in name) {  // Circular name properties in an object name  
    namestring += name[props];   
alert(namestring);  //NAME2NAME4   
alert("name1" in name); //false   
alert("name4" in name); //true  

Note that the properties of the object is not in order.

Each object's constructor property of a javascript object has a constructor property. This attribute corresponds to the object is initialized when the constructor function (the function is object).
var date = new Date();   
alert(date.constructor);  //Date   
alert(date.constructor == "Date");  //false   
alert(date.constructor == Date);  //true  
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of JavaEye javascript object-oriented technology foundation (1)

  • JAVA Class naming convention

    1. Entity Layer: Inheritance: All categories inherited from BasicEntity, one of BasicEntity implementation interface; Naming rules: Class Name = Object + type suffix, one of type suffix for Bean, such as: SalesOrderBean 2. Form l ...

  • Hibernate configuration parameters

    Hibernate in the configuration file: <properties> <property name="" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • Great collection of java interview topics

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries