Custom Search

How can we create a class in JavaScript using Atlas?

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’s 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 which 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.

Below figure has two important code snippets the top one is taken from components.js it defines the class definition and the second code snippet is of ASPX page which consumes the JavaScript class. So let’s understand all the numbered points one by one. 1 - In this section we register namespace using registerNameSpace function. We have named our namespace as NameSpaceCustomer. 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.

Your Ad Here