Oxscript-object-oriented extension for JScript (TM) (PreView)

Source: Internet
Author: User

Recently, we have made object-oriented extensions for JScript so that you can define classes in JScript (TM) and write real object-oriented code.

I named the extended JScript oxscript. The features to be implemented are as follows:

Oxscript is an object-oriented extension for JavaScript.

The following features will be provided by oxscript:

1. class definition;

2. Final class;

3. abstract class;

4. Inheritance;

5. Overriding;

6. abstract function;

7. polymorphism;

8. package;

9. Property getter/setter;

10. Reflection (readonly );

The general specification is as follows:

[Access modifiers]

Public, protected, private,

Static, abstract, final, virtual

[Directives]

$ Include, $ import,

$ Package, $ class,

$ Field, $ method, $ property, $ event

[Additional keywords]

Extend, implement,

Public, protected, Private, static,

Get, Set

[Additional operators]

Classof, raise

[Predefined classes]

Class package extend object {

Public:

Protected:

PRIVATE:

}

Class class extend object {

Public:

Protected:

PRIVATE:

}

Class member extend object {

Public:

Protected:

PRIVATE:

}

Class field extend member {

Public:

Protected:

PRIVATE:

}

Class Method extend member {

Public:

Protected:

PRIVATE:

}

Class property extend member {

Public:

Protected:

PRIVATE:

}

Class event extend member {

Public:

Protected:

PRIVATE:

}

[Class hierarchy]

Oxscript. Object

| -- Oxscript. Number

| -- Oxscript. String

| -- Oxscript. Boolean

| -- Oxscript. Date

| -- Oxscript. Array

| -- Oxscript. enumerator

| -- Oxscript. Function

| -- Oxscript. Regexp

| -- Oxscript. vbarray

| -- Oxscript. Error

| -- Oxscript. activexobject

|

| -- Oxscript. reflection. Package

| -- Oxscript. Class

| -- Oxscript. reflection. Member

| -- Oxscript. reflection. Field

| -- Oxscript. reflection. Method

| -- Oxscript. reflection. Property

| -- Oxscript. reflection. Event

The following is a sample code:



// Namespace declarations

VaR

Laserpackage = $ package ();


With (laserpackage ){

// Define a class named oxscriptdemo in laserpackage

$ Class ([public, final], oxscriptdemo, {extend: oxscript. Object },

// Construcltor

Function oxscriptdemo (){

// This is the constructor Implementation of class laserpackage. oxscriptdemo

},

{

// Public members

Public :{

// A field with type of oxscript. Number

Field1: $ field (oxscript. Number ),

// A method definition

Method1: $ method (

Function (){

// Implementation of Method1

}

),

// A property of Type oxscript. String having both getter and setter

Property1: $ property (

Oxscript. string,

{

Get: function (){

// Getter of property1

},

Set: function (){

// Setter of property1

}

}

),

// An event Declaration

Event1: $ event (

Function (source, eventargs) {}// the function declaration of event1 Handler

),

// An event handler for event1

Event1handler: $ method (

Function (source, eventargs ){

// Implementation of event handler

}

),

// The method which demonstrats how to access the class members and raise events

Demomethod: $ method (

Function (){

// Assign a value to field1

This. field1 = 66;

// Call Method1

This. Method1 ();

// Get property1

VaR STR = This. get_property1 ();

// Set property1

This. set_property1 (STR );

// Add a handler to event1

This. event1.add (this. event1handler );

// Raise event1

Raise (this. event1 );

}

)

},

// Protected members

Protected :{

//

},

// Private Members

PRIVATE :{

//

}

}

);

}

Oxscript uses the flexible syntax and features of JScript to package it. Therefore, you do not need to install it. You only need to reference oxscript on the page. javascript can enjoy simulated object-oriented programming. In addition, oxscript also provides a useful feature that can reflect the definition information of the class, and then automatically generate a reference form similar to objectbrowser in, lists all the classes used on the current page and their member definitions, so as to provide programming references to assist in script writing. The younger brother is currently fully developing (it is estimated that the first version can be released within one week). He first posts the design idea and code preview for discussion and communication. Please give more valuable comments.

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.