Business:
The flexibility of 1.1 JavaScript
Object-oriented JavaScript programming mode: 1, you can save the state 2, with the object to call the method 3, the written program to master its structure, can withstand the iterative development (personally think)
Copy Code code as follows:
Enough to create a function, also known as a class
var anim=function () {
...
}
The methods in the class, the prototypes in JavaScript
Anim.prototype.start=function () {
...
}
Note: The general method is put into the prototype, because the general store in the prototype is not changed to common things
Code
Copy Code code as follows:
Function.prototype.method=function (NAME,FN) {
THIS.PROTOTYPE[NAME]=FN;
}
var anim=function () {
}
Anim.method ("Start", function () {alert ("Started")})
Anim.method ("Stop", function () {alert ("stopped")})
var anim=new anim ();
Anim.start ();
Anim.stop ();
The code above highlights a few points:
1. All function is the object of this class of function such as Var f=new function ("alert ();")
2, we can also go to the system default class prototype to add methods, but this does not advocate, easy to confuse
A function is a first-class object:
Anonymous functions can create closures (closures will open a separate chapter for learning)