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: