JavaScript Object View

Source: Internet
Author: User

JavaScript Object View

As we all know, the current JavaScript implementation of the ecma262 specification is based on objects. In the future, javascript2.0. object-based methods can also be used for both object-oriented and backward compatibility, but we will not discuss it before we see the official version.
Object-based. What is object-based? Beginners are usually confused with object-oriented. So what is object-based? To identify (purely personal opinion) Objects Based on objects are not equal to object-oriented objects; object-based layers are higher than object-oriented objects; Objects Based on objects use existing objects or extended existing objects, object-oriented is to design or abstract a new object. At the same time, this object has the characteristics of inheritance, polymorphism, encapsulation, and so on. From another perspective, we can also think that object-based systems are on the shoulders of object-oriented systems.
Since object-based systems are built on the shoulders of object-oriented systems, Object-based systems naturally have the characteristics of object-oriented languages, such as JavaScript (This article focuses on it, and others include ActionScript ). How does JavaScript implement object-oriented processing? Well, that's why we talked so much nonsense. The purpose of this article is to explain how to use object-oriented in JavaScript.
In the second part of "conquer RIA-JavaScript-based Web Client development", the second part of "javascript advanced" briefly describes the Object Features of JavaScript. That's right! Because of these features, JavaScript today has been created (I forgot to say that JavaScript designers didn't seem to have found that JavaScript has so many features ).
The creation, use, and inheritance of objects will not be long-winded here. You can refer to the advanced article "conquer RIA-JavaScript-based Web Client development". Of course, you are also welcome to take a brick. (I often on the blog-http://hi.baidu.com/nathena)
In the world of object-oriented programming, design patterns are often inseparable. Naturally, now we have talked about object-oriented, and naturally we have introduced design patterns. Haha, do you think there is a feeling of being fooled? By the way, I just want to introduce the design pattern in Javascript. Well, no nonsense. A few simple introductions
Singletion (singletion)
View http://hi.baidu.com/nathena/blog/item/714948dd65b25e325882dd0d.html
VaR singletion = {
Constructor: function ()
{
// Ensure the uniqueness of the Instance
// Note that this cannot be used
Return singletion;
},

Basepay: 4500,
Allowance: 200,
Dutf-8: 2000,
Other: 3000,
Affixation: 1000
}

VaR A = singletion;
VaR c = new (singletion. constructor )();
Alert (A = C)
Adapter)
View http://hi.baidu.com/nathena/blog/item/12b9882c7887a3eb8a1399af.html
Funtion stack ()
{
// Adapt to the JS array Interface
VaR d = [];
// Actually, only peek, Pop, push, search, and isempty are required.
This. Peek = function ()
{
Return d [0];
}

This. Pop = function ()
{
Return D. Pop ();
}

This. Search = function (o)
{
For (VAR I = 0; I <D. length; I ++)
{
If (d [I] = O)
Return I;
}
}
This. isempty = function ()
{
Return D. Length = 0? True: false;
}
}
Composite Combination Mode
VaR win = function ()
{

}

VaR wall = function ()
{
}

VaR door = function ()
{
}
VaR room = function ()
{
This. Win = new win ();
This. Wall = new wall ();
This. Door = new door ();
}
And so on .................
For more information, see
Http://hi.baidu.com/nathena/blog/category/web%C7%B0%B6%CB%BC%BC%CA%F5
You can shoot bricks. Welcome to shoot bricks !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.