Atlas tour of Rats: Quick Start namespace

Source: Internet
Author: User
Tags javascript extension
Atlas JavaScript Extension: namespace)
Namespace allows you to combine some common functional functions into the same namespace. The following example shows how to add the class "person" to the namespace demo, the method is: type. registernamespace and type. registerclass.
First, we will add pages to the sites for those experiments.
First, we add a JS file. Its main function is to register a demo namespace and register the class person in the namespace demo.
Right-click the site and select Add new item. In the displayed dialog box, select JScript file named namespace. js.
Write as follows: Code :
Type. registernamespace ("Demo ");
// Register a namespace demo first
// Add classes to the namespace
Demo. Person = function (firstname, lastname, emailaddress ){
VaR _ firstname = firstname;
VaR _ lastname = lastname;
VaR _ emailaddress = emailaddress;
// Class Method
This. getfirstname = function (){
Return _ firstname;
}

This. getlastname = function (){
Return _ lastname;
}
}
// Registration type
Type. registerclass ('demo. person', null, Web. idisposable );
In solution manager, right-click the site and select Add new item. In the displayed dialog box, select Web form and name namespace. aspx, remove the code suffix and select the small check mark before the mater page, click Add, in namespace. in the Code view of aspx, we still modify the xhtm document type declaration as follows:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Remove <SCRIPT runat = "server"> </SCRIPT>.
Modify <title> to namespace.
Then, after the </title> mark, add the following references to the Atlas JS script library in the <Atlas: script id = "script1" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Mozilla "/>
<Atlas: script id = "script2" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Firefox "/>
<Atlas: script id = "script3" runat = "server" Path = "~ /Scriptlibrary/atlasruntime. js "/>
In this example, we can remove the form mark. In the <div> tag, place a phrase and a button as follows:
In this example, we will add the person class to the namespace of demo. <br>
<Input type = "button" value = "add class to namespace" onclick = "Return thisclick ();" id = "button1"/>
The written code is as follows, with comments:

<% @ Page Language = "C #" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> namespace </title>
<Atlas: script id = "script1" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Mozilla "/>
<Atlas: script id = "script2" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Firefox "/>
<Atlas: script id = "script3" runat = "server" Path = "~ /Scriptlibrary/atlasruntime. js "/>
</Head>
<Body>
<Div>
In this example, we will add the person class to the namespace of demo. <br>
<Input id = "button1" value = "add the person class to the demo space" type = "button" onclick = "Return thisclick ()"/>

</Div>
<SCRIPT type = "text/JavaScript" src = "namespace. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function thisclick ()
{
// Defines the object variables of the person class. There are three parameters.
VaR testperson = new demo. Person ('rat ', 'Master Wu banwa', 'pwqzc1688 @ Google.com ');
// Call the two methods of the person class to obtain the first parameter and the second parameter dialog box.
Alert (testperson. getfirstname () + "is the apprentice of" + testperson. getlastname () +! ");
// Return false again. Of course, return thisclick in the button clicking event to prevent the JS console from being popped up in other browsers.
Return false;
}
</SCRIPT>
</Body>
</Html>

You must note that <SCRIPT type = "text/JavaScript" src = "namespace. js"> </SCRIPT>
Cannot be written as <SCRIPT type = "text/JavaScript" src = "namespace. js"/>
I don't know why thisclick does not define JS errors!
I have not captured a graph yet. Now I want to capture a graph to see the effect! Is the figure captured in Firefox:

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.