The latest version of dojo is 1.3.1. Remember that it was 0.4 in. The number of documents increases gradually, and the number of dojo-based documents increases gradually. Dojo also released the core version, which is only 27kb after compression. , Dojo. js write Class Method
The latest version of dojo is 1.3.1. Remember that it was 0.4 in. The number of documents increases gradually, and the number of dojo-based documents increases gradually. Dojo also released the core version, which is only 27kb after compression. In dojo, the dojo. declare method is used to define a class. The source code of dojo. declare will not be posted here. Dojo. declare has three parameters,
Parameter 1: Class Name className
Parameter 2: inherited class superclass
Parameter 3: constructor, method props
To define a class, you only need to pass the first and third parameters. This is because we only discuss how to define a class and do not discuss inheritance. The Code is as follows:
The Code is as follows:
// Define the class name
Var className = "Person ";
// Define the constructor and Method
Var proto = {
Constructor: function (name) {this. name = name ;},
GetName: function () {return this. name ;},
SetName: function (name) {this. name = name ;}
}
// Define the class Person
Dojo. declare (className, null, proto );
// Create an object
Var p = new Person ("tom ");
Console. log (p. getName (); // tom
P. setName ("jack ");
Console. log (p. getName (); // jack
// Test whether instanceof and p. constructor correctly point to Person
Console. log (p instanceof Person); // true
Console. log (p. constructor === Person); // true