Prototype 1.5 & amp; scriptaculous 1.6.1 Study Notes

Source: Internet
Author: User

Otalk was developed based on prototype1.4 recently. Later, Because I added scriptaculous 1.6.1, she requested that the prototype version be 1.5, so it was upgraded to 1.5, I watched the demo learn the usage of scriptaculous.
The usage will be sorted out later, because the results won't be satisfied many times during the use process, and I can't understand the code. After a torment, I made up my mind, be sure to understand the scriptaculous and prototype code!

Here, as my study notes, there may be no logic in order. Wait until the study is complete and finally sort it out.

First of all, the definition class looks at some introductions from the smiling teacher. I think it is a test. Many things are often understood, but it is still a lot worse.

Var Class = {
Create: function (){
Return function (){
This. initialize. apply (this, arguments );
}
}
}

Defines a class function as a template or prototype for creating a class.
Usage
Var llinzzi = Class. create ();
Llinzzi. prototype = {
Initialize: function (){
Document. write ('instance created ');
},
Fun1: function () {document. write ('method called by instance ');}
}

Var linChild = new llinzzi ();
Run, the output 'instance created 'indicates that initialize is called when the instance is created.
Reviewing the Class code
Return function (){
This. initialize. apply (this, arguments );
}
It can be seen that when the create method is executed, it is called.
LinChild. fun1 ();
Output 'method called by instance', fun1 method called successfully
This means that when the prototype Class. create (); method is used to create an object, initialize is used as a special method and executed during instance creation for initialization.

Continued commitment
Object. extend = function (destination, source ){
For (var property in source ){
Destination [property] = source [property];
}
Return destination;
}

Usage
Object. extend (target, source );
What surprised me was a piece of code in scriptaculous.
Var options = Object. extend ({
Greedy: true,
Hoverclass: null,
Tree: false
}, Arguments [1] | | {});
Why the Object. extend method is used to define an options?
Direct
Var options = {
Greedy: true,
Hoverclass: null,
Tree: false
}
Isn't that enough? And so on. arguments [1] | |{} is next to it. This should be the target, and the target is the function parameter. After analysis, obtain the parameter, if this parameter is not provided, it is a fear that {} is used. If yes, it is also in the format of {hoverclass: 'xx'}. Oh, it is not that simple to define options, check whether there are any parameters. the extend method appends or overwrites the objects in the parameter to the previous {greedy: true, hoverclass: null, tree: false}. If the parameter is none, the preceding var options ={}; is quite simple. But what if {hoverclass: 'abc'} is included in the parameter? At this time, the original hoverclass value is overwritten null. Then, we can see that the return value of the Object. extend method is the full value after the first parameter is overwritten.
I have to admire it. I have defined it in one sentence and set the default value.
The more interesting you are, the more interesting you are.

Related Article

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.