Atlas document: Making JavaScript easier simplified Javascript development

Source: Internet
Author: User
Notes: For the Atlas Series Article To maintain the taste of the original
Try not to delete the section during the process. In order to ensure readability and consistency, this article provides an English comment on some vocabulary translation. Due to limited ability, there may be omissions and mistakes in the translation and learning process.
Give more advice. In general, this part of translation is only an introduction and generalization. For more details, refer to other articles on Atlas in the garden.

Original article address: here
Translation: Fan weixiao

ASP. NET Atlas allows you to write gorgeous and interactive web applications using JavaScript on your browser.Program. Atlas extends the type system to JavaScript to provide naming controls, inheritance, interfaces, enumeration, and helpers for strings and arrays ). These extensions allow you to write Atlas applications in a structured manner, improving maintainability and adding features more easily.

In this section, you will learn how to use the following JavaScript Atlas extensions:
Namespaces)
Inheritance)
Interface)

Use namespace:

Namespace allows you to group common functions. The following example demonstrates how to use the type. registernamespace and. registerclass methods to add a person class to the namecontrol demo.

First, add scriptmanager to your page, register a namespace, create a class, and then register this class: Type. registernamespace ("Demo");

Demo. Person =   Function (Firstname, lastname, alias)
{
VaR _ Firstname = Firstname;
VaR _ Lastname = Lastname;

This . Getfirstname =   Function (){
Return _ Firstname;
}


}
Demo. Person. registerclass ('demo. person ', Null , Web. idisposable );

Inheritance:

In the following example, the script contains two classes: person and employee inherited from person. Both classes have private fields (fields) and common attributes and methods. In addition, the override class overwrites the tostring implementation. In this way, we can use the functions of the base class. Type. registernamespace ("Demo");

Demo. Person=   Function (Firstname, lastname, emailaddress ){
VaR _ Firstname = Firstname;
VaR _ Lastname = Lastname;
VaR _ Emailaddress = Emailaddress;

This . Getfirstname =   Function (){
Return _ Firstname;
}



This . Dispose =   Function (){
Alert ('bye' +   This . Getname ());
}
}
Demo. Person. registerclass ('demo. person ', Null , Web. idisposable );

Demo. Person. Prototype. tostring= Function(){
Return This. Getname ()+'('+ This. Getemailaddress ()+')';
}

Demo. Employee =   Function (Firstname, lastname, emailaddress, team, title ){
Demo. employee. initializebase ( This , [Firstname, lastname, emailaddress]);

VaR _ Team = Team;
VaR _ Title = Title;

This . Getteam =   Function (){
Return _ Team;
}
This . Setteam =   Function (Team ){
_ Team = Team;
}


}
Demo. employee. registerclass ('demo. Employee ', demo. person );

Demo. employee. Prototype. tostring =   Function (){
Return Demo. employee. callbasemethod ( This , 'Tostring ') + '\ R \ N' +   This . Gettitle () + '\ R \ N' +   This . Getteam ();
}

Interface:

This example defines the base class animal, ipet interface and two subclasses dog and cat that implement the ipet interface, but the subclass tiger does not inherit this interface.

Type. registernamespace ("Demo. Animals");

Demo. Animals. ipet= Function(){
This. Getfriendlyname=Function. abstractmethod;
}
Demo. Animals. ipet. registerinterface ('demo. Animals. ipet ');

Demo. Animals. Animal =   Function (Name ){
VaR _ Name = Name;

This . Getname =   Function (){
Return _ Name;
}
}
Demo. Animals. Animal. registerabstractclass ('demo. Animals. Animal ');

Demo. Animals. Animal. Prototype. tostringcustom= Function(){
Return This. Getname ();
}
Demo. Animals. Animal. Prototype. Speak=Function. abstractmethod;

Demo. Animals. Pet =   Function (Name, friendlyname ){
Demo. Animals. Pet. initializebase ( This , [Name]);

VaR _ Friendlyname = Friendlyname;
This . Getfriendlyname =   Function (){
Return _ Friendlyname;
}
}
Demo. Animals. Pet. registerabstractclass ('demo. Animals. Pet ', demo. Animals. Animal, demo. Animals. ipet );

Demo. Animals. Cat= Function(Friendlyname ){
Demo. Animals. Cat. initializebase (This, ['Cat', friendlyname]);
}
Demo. Animals. Cat. registerclass ('demo. Animals. cat', demo. Animals. Pet );

Demo. Animals. Cat. Prototype. Speak= Function(){
Alert ('meow ');
}

Demo. Animals. Cat. Prototype. tostringcustom= Function(){
Return'Pet'+Demo. Animals. Cat. callbasemethod (This, 'Tostringcustom ');
}

demo. animals. felix = function () {
demo. animals. felix. initializebase ( This ,[ 'Felix ']);
}< br> demo. animals. felix. registerclass ('demo. animals. felix ', demo. animals. CAT);

demo. animals. felix. prototype. tostringcustom = function () {
return demo. animals. felix. callbasemethod ( T His , 'tostringm m') + 'its Felix ! ';
}

Demo. Animals. Dog= Function(Friendlyname ){
Demo. Animals. Dog. initializebase (This, ['Dog', friendlyname]);
}
Demo. Animals. Dog. registerclass ('demo. Animals. dog', demo. Animals. Pet );

Demo. Animals. Dog. Prototype. Speak= Function(){
Alert ('woof ');
}

Demo. Animals. Tiger= Function(){
Demo. Animals. Tiger. initializebase (This, ['Tiger ']);
}
Demo. Animals. Tiger. registerclass ('demo. Animals. Tiger ', demo. Animals. Animal );

Demo. Animals. Tiger. Prototype. Speak= Function(){
Alert ('grrr ');
}


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.