Method 7 of javascript writing

Source: Internet
Author: User

, 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: Copy codeThe 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

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.