How can we create a class in JavaScript using Atlas?

 Posted by ArticlesMaint on 10/1/2009 | Category: ASP.NET AJAX Interview questions | Views: 4017

JavaScript is object based language and this a new feature which is provided by Atlas. Using Atlas you can now define classes, do inheritance, create interfaces etc in JavaScript. You can now implement all the object-oriented concepts in JavaScript. So let us understand the same with an example.
Once you install the Atlas setup you will get the following JS files and a web.config file as shown in the below figure. In order to use Atlas you need to add the JS files in your project. You can see from the figure below we have added the JavaScript files and the web.config file to the project that was installed with Atlas setup. We also need to add Microsoft.Web.Atlas.dll to the project.Components.js has the class definition, which we will discuss in the coming sections.

Figure 18.4:- Ajax folder structure

Below figure has two important code snippets the top one is taken from components’ it defines the class definition and the second code snippet is of ASPX page which consumes the JavaScript class. So let us understand all the numbered points one by one.

  1. In this section we register namespace-using register Namespace function. We have named our namespace as Namespace Customer. 

  2. Here we have defined our class clsCustomer.

  3. We have defined two properties Customer Code and Customer Name. Both the properties have get and set function. We have also defined a read-only function getCodeAndName, which returns the concatenation of customer code and customer name.

  4. Finally we register the class with the namespace.

  5. In this section we have consumed the class.getCOdeAndName will display the concatenated value of customer code and customer name.

    Note: - You can find the above code in AtlasClass folder. Feel free to experiment with the same.

Figure 18.5:- Code snippet for consuming the class

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response