Recently, I started with otalk, which was based on prototype1.4. Later, because I added scriptaculous 1.6.1, she asked the version of prototype to be 1.5, so she upgraded to 1.5. I learned how to use scriptaculous when I watched demo.
I will sort out the usage later, because the effect is not satisfied many times during use, and I want to read the code but can’t understand it. After a torture, I made up my mind to understand the scriptaculous and prototype codes!
Here is my study notes, there may be no logic in order. When I finish my study, I will sort it out.
First of all, the definition class. Looking at some introductions from Teacher Xiaoxiao, I saw it myself and tried it. Often, I realized many things after reading them, but in fact they were still much worse.
var Class = {
create: function() {
return function() {
(this, arguments);
}
}
}
Define a class function as a template or prototype for creating the class
How to use
var llinzzi= ();
= {
initialize:function(){
('Instance was created');
},
fun1:function(){('The method is called by the instance');}
}
var linChild = new llinzzi();
Run, output 'instance is created' indicating that initialize is called when creating the instance
Review the Class code
return function() {
(this, arguments);
}
It can be seen that when the create method is executed, the call starts.
linChild.fun1();
Output 'Method is called by the instance', fun1 method is successfully called
That is, when the prototype(); method is used to create an object, initialize is executed as a special method when creating an instance and is used to initialize.
Continued
= function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
usage
(target, source);
What makes me strange is a piece of code in scriptaculous
var options = ({
greedy: true,
hoverclass: null,
tree: false
}, arguments[1] || {});
Since it is to define an option, why do you still need to use methods?
direct
var options ={
greedy: true,
hoverclass: null,
tree: false
}
Isn't it enough? Wait, there are problems. There are arguments[1]||{} later. This should be the target. The target is the parameter of the function. After analysis, obtain the parameters. If there is no such parameter, it is {}, which is {}. If there is, it is also in the format of {hoverclass:'xx'}. Oh, it turns out that defining options is not that simple. First, see if there are parameters. Whether there are or not, use the method to append or overwrite the object in the parameter to the previous { g reedy: true, hoverclass: null, �
I have to admire that I define it one sentence after another, and the default value is set.
The more you watch, the more interesting it becomes, keep watching
I will sort out the usage later, because the effect is not satisfied many times during use, and I want to read the code but can’t understand it. After a torture, I made up my mind to understand the scriptaculous and prototype codes!
Here is my study notes, there may be no logic in order. When I finish my study, I will sort it out.
First of all, the definition class. Looking at some introductions from Teacher Xiaoxiao, I saw it myself and tried it. Often, I realized many things after reading them, but in fact they were still much worse.
var Class = {
create: function() {
return function() {
(this, arguments);
}
}
}
Define a class function as a template or prototype for creating the class
How to use
var llinzzi= ();
= {
initialize:function(){
('Instance was created');
},
fun1:function(){('The method is called by the instance');}
}
var linChild = new llinzzi();
Run, output 'instance is created' indicating that initialize is called when creating the instance
Review the Class code
return function() {
(this, arguments);
}
It can be seen that when the create method is executed, the call starts.
linChild.fun1();
Output 'Method is called by the instance', fun1 method is successfully called
That is, when the prototype(); method is used to create an object, initialize is executed as a special method when creating an instance and is used to initialize.
Continued
= function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
usage
(target, source);
What makes me strange is a piece of code in scriptaculous
var options = ({
greedy: true,
hoverclass: null,
tree: false
}, arguments[1] || {});
Since it is to define an option, why do you still need to use methods?
direct
var options ={
greedy: true,
hoverclass: null,
tree: false
}
Isn't it enough? Wait, there are problems. There are arguments[1]||{} later. This should be the target. The target is the parameter of the function. After analysis, obtain the parameters. If there is no such parameter, it is {}, which is {}. If there is, it is also in the format of {hoverclass:'xx'}. Oh, it turns out that defining options is not that simple. First, see if there are parameters. Whether there are or not, use the method to append or overwrite the object in the parameter to the previous { g reedy: true, hoverclass: null, �
I have to admire that I define it one sentence after another, and the default value is set.
The more you watch, the more interesting it becomes, keep watching