Object-oriented development of JavaScript under Microsoft AJAX Library

Source: Internet
Author: User

JavaScript should not be unfamiliar to people who have done Web applications, initially to do some simple form validation, basically playing with some technical things. JavaScript is not an object-oriented language, not a development platform, but JavaScript provides a very powerful prototype-oriented object-oriented invocation feature that allows us to use them where we need them. ASP.net Ajax also provides support for JavaScript-oriented type systems.

In object-oriented languages such as C#,java, namespaces, classes, interfaces, methods, and so on are not unfamiliar to everyone, so have you ever used JavaScript on a client to write an object-oriented program? For details, see decomposition below:

A, namespace

What is a namespace? The role of namespaces is to organize a large number of types so that developers can easily find the types they need. Like most object-oriented languages, JavaScript provides a way to register namespaces based on prototype, see syntax:

Type.registerNamespace ("Mynamespae");

For example, to register a namespace for "Com.cnblogs.beniao," use the following code to define:

1//Registration namespace
2type.registernamespace ("Com.cnblogs.beniao");

In actual development, namespaces can be registered repeatedly, preferably by registering namespaces before each individual script module to ensure that namespaces exist.

Second, the class

In object-oriented programming language, the definition of class is the collective name of objects with the same attributes, operations, and relationships. What about the client javascript? I think it's just that, unlike in object-oriented languages, which is defined by class, it has a proprietary syntax, see below:

1 register a class
2type.registerclass ("TypeName");

For example, to register a class named "Com.cnblogs.beniao.Employee", "Com.cnblogs.beniao" registers the code for the namespace as follows:

1//registers a Com.cnblogs.beniao.Employee class
2type.registerclass ("Com.cnblogs.beniao.Employee");

A class can be seen as an object that is abstracted, he should have construction methods, member fields, and related operations, which are common in object-oriented programming, and this feature is no exception in client JavaScript, where JavaScript is based on prototype You can also provide constructors and member fields and related operations for the classes registered by JAVASCRPT, and look at the following analysis:

Related Article

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.