There is a saying in Buddhist Scriptures: Do not donate. This means that the effects of all your efforts may not be present or in the future, but it will make sense if you do. Our mentality is peaceful, and we will gradually promote it and gradually improve it, which will be meaningful to the future.
Some people support a certain type of database or framework very narrowly. In fact, good things are mutually infiltrated. Like jquery, it provides Dom operations, but this is not enough. Do not look at the front-end by adding, deleting, modifying, or querying data in the background. The front-end display is very colorful. The background is not so boring, and of course the same is true for incompetent people. They always have excuses to avoid learning and ask people to solve project problems. Such an IT career can only support up to 30 years old. We focus on one thing. Other products of the same type are of great reference value and can broaden our thinking. For example, prototype. JS, which first dominated the Javascript field, was born as an auxiliary project of rails. Drawing on the real Ruby design where everything is an object, prototype. js swept across the world that year, and no one can beat it. We can see that many of its method names are taken from the ruby standard library. A powerful library like base2, I think it also draws a lot of inspiration from prototype. js. Mootools is called prototype. js and the framework is prototype, but many implementations are changed from base2. All of these three have a powerful Inheritance Mechanism. After learning one of them, it is easy to get started with the other two. In other words, your smart investment will not be in vain.
The open-source world in the West is very active, and new class libraries have a strong known framework. Rightjs is an example. I cannot help but explain the two modules.
The options module is used to process parameters. There are already signs of this in the famous prototype special effect library. Mootools is simply handed over to object. Reset for this rough job. Why? Because we usually need to input an attribute package to configure the newly generated class, add class members, instance members, and so on for it, and even plan to configure the membership in the blueprint of mootools2. This is actually implemented using the protect method in mootools1.2.4, but it wants to be more smart.
Options = {setoptions: function (options) {// integrates the options attributes of two objects. One is the attribute package used for configuration and the other is a new class. Note that the options module cannot operate independently, // It must be used in other modules or classes. VaR Options = This. options = object. merge (class. findset (this, 'options'), options), match, key; // if its on attribute is a function, the execution method, such as this. on ("click", function () {}) if (isfunction (this. on) {for (key in options) {If (match = key. match (/on ([A-Z] [A-Za-Z] +)/) {This. on (Match [1]. tolowercase (), options [Key]); Delete (options [Key]) ;}}return this ;}, // Since the rightjs class factory has a maximum of two parameters, the parent class and the object used as the property package are now used to obtain the property package cutoptions: func Tion (ARGs) {var ARGs = $ A (ARGs); this. setoptions (ishash (ARGs. Last ())? Args. Pop () :{}); Return ARGs ;}};
The following is the observer module. Many of its methods support multiple parameter passing forms. Like jquery, logic is complicated and disgusting.
Observer = new class ({include: Options,/*** General constructor ** @ Param object options */initialize: function (options) {This. setoptions (options); Observer. createshortcuts (this, class. findset (this, 'events');}, // This. on ("click", fncallback) // Add the callback function and its event name. The additional parameter on: function () {var ARGs = $ A (arguments), event = args. shift (); If (isstring (event) {// create a $ listeners to store special objects. If (! Defined (this. $ listeners) This. $ listeners = []; var callback = args. shift (), name; Switch (typeof callback) {Case "string": Name = callback; callback = This [callback]; Case "function": var hash = {}; // don't move it in the one-line hash variable definition, // it causes problems with the Konqueror 3 later on hash. E = event; hash. F = callback; hash. A = ARGs; hash. R = Name; this. $ listeners. push (hash); break; default: If (isarray (callback) {for (VAR I = 0; I The Observer mode allows custom classes to have associated operations like event systems. As soon as they change, they are very helpful for decoupling. From the initial class to options to observer, it splits all the things that can be disassembled. This modular design is very beneficial for us to learn. Like jquery, it follows another path and uses a large number of plug-ins to make up for the functions of its core library. Of course, it also absorbs some excellent methods from time to join the core library. However, no matter how hard it is, the ability of the class library is still very limited, and it is not comparable to this fully scalable framework. For JavaScript learning, a framework like prototype can help you gain more benefits.