首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

GI Summary - Jan 28, 2011: 怎么在GI中定义Class

2012-10-30 
GI Summary - Jan 28, 2011: 如何在GI中定义Class.1. GI的JS框架中也有类似Java的Reflect的特性,比如forNa

GI Summary - Jan 28, 2011: 如何在GI中定义Class.
1. GI的JS框架中也有类似Java的Reflect的特性,比如forName()方法。
2. GI的JS中也是单根继承, 可以实现多个接口。需要定义constructor,名字必须是init(). Class/Interface中可以定义成员方法, 静态方法和抽像方法,成员变量,静态变量.
例子在下面一断代码块里, 从GI的API里拷出来的。

/*You may obtain an instance of jsx3.lang.Class in one of the following ways: */var c = jsx3.Class.forName("jsx3.Object");var c = jsx3.Object.jsxclass;/*This class is also used for defining classes. Use one of defineClass and defineInterface to define a class in the JSX class hierarchy. Note that any class defined in the package jsx3.lang is aliased into the jsx3 package. Therefore jsx3.lang.Object may also be referenced as jsx3.Object. The following are class nomenclature definitions using jsx3.lang.Object as an example:*//*jsx3.lang — the package, an instance of (JavaScript, not JSX) Object jsx3.lang.Object — the class constructor, instance of Function jsx3.lang.Object.jsxclass — the class, instance of jsx3.lang.Class jsx3.lang.Object.prototype — the class prototype, instance of Object The following is an example of how to define a new class called Example in package eg: */jsx3.lang.Class.defineClass(  "eg.Example",                   // the full name of the class to create  eg.Base,                        // the class extends eg.Base  [eg.Comparable, eg.Testable],   // the class implements interfaces eg.Comparable and eg.Testable  function(Example) {             // name the argument of this function "Example"        // every class must define an init method since it is called automatically by the constructor    Example.prototype.init = function(arg1) {      this.arg1 = arg1;    };    // define an instance method like this:    Example.prototype.instanceMethod = function() {      ...    };    // define an abstract method like this:    Example.prototype.abstractMethod = jsx3.Method.newAbstract();    // define a static method like this:    Example.staticMethod = function() {      ...    };    // define a static field like this:    Example.STATIC_FIELD = "...";    // define an instance field like this:    Example.prototype.instanceField = "...";  });

热点排行