Javascript Implementation for ESOE 0.2 | ||
Modules![]() | ||
ESOE of current version includes 6 modules.
| esoe.js | M1 : kernel | 1. Name space definition 2. Class definition 3. Class deriving 4. Keywords definition 5. Module loading 6. Debug tool | 1. Support script language compatible with ECMA-262 3rd. 2. Manually load classes and libraries. 3. The release version of an application can use only M1 for efficiency. |
| esoe2.js | M2 : resource | 1. Physcal mapping of name space. 2. Resource loading. | |
| esoe3.js | M3 : loader | 1. Automatically classes loading. | 1. M3 depend on M2. |
| _update.js | Update tool for M3 | ||
| esoe4.js | M4 : destroy | 1. Destroy mechanism | 1. A temprorary module. 2. M4 may be related to all other modules. |
| esoe5.js | M5 : share | 1. Class sharing 2. Share the ESOE itself |
ESOE Parameters![]() | ||
ESOE object has below properties that can be loaded from external.
| src | ESOE engine M1 file |
| module | String to indicate which modules are to be loaded. Module numbers are separated by ','. Acceptable module number are "1","2","3","4","5". Example: "1" M1 (default) "2" M1+M2 "4,5" M1+M4+M5 |
| debug | Debug level parameter, current version support bellow value, 0: no debug (deault) 1: the lowest debug level 9: the highest debug level |
| nokey | c2 keyword list to be forbidden. if "*" all c2 keywords forbid |
| libpath (M2) | Default library path, only one path can be set. If not set, use _path as _libpath. |
| libmode (M3) | The mode of loading classes and libraries. 0: do not automatically load library or class file (default). 1: load package library firstly( _all.js ), then class file. 2: load class file firstly, then package library. 3: load package library only 4: load class file only Note: 1. For an actual application, not all of the mode can work correctly. It should be set according to environment of the application. |
| nodestroy (M4) | Parameter to close the destroy mechanism, 0: don't close, default 1: close the destroy mechanism |
_ns![]() | ||
_ns= function( ns [, root [, obj]] )
Pre-define a name space or get an object by its name space.
ns
name space string
root
the relative obejct of the name space. If omit, use $esoe.ns
obj
the obejct that is to map to the ns. If omit, create a new Object object.
return
the existed or created object mapped to the ns
Ex
_ns("MyPkg.sub.Class3");
_ns("MyPkg.sub.Class3",myns);
_ns("MyPkg.sub.Class3",myns,myobj);
_normalize![]() | ||
_normalize= function ( ns [, func [, bNonEsoe [, bObject [, bConflict]]]] )
Load a constructor to a name space item
ns
name space string
func
constructor/function, can be omitted if the func has pre-normalized to the ns.
bNonEsoe
set 1 if normalizing a non-esoe function.
bObject
set 1 if normalizing a non-esoe object.
bConflict
set 1 if any keyword of c3 keywords conflict.
return
the normalized object; if fail, return null.
Ex:
If( !_normalize("MyPkg.Class1") ) return false; // normalize esoe style class
// normalize non-esoe style class
_normalize( "com.yahoo.yui.widget.Node", YAHOO.widget.Node, 1 );
// normalize non-esoe object
_normalize( "com.yahoo.yui.widget.TVAnim", YAHOO.widget.TVAnim, 1, 1 );
_derive![]() | ||
_derive= function ( ns [, func], nsBase )
Derive a class from a base class
ns
name space string
func
the constructor that is to be derived from the base class. It can be omitted if the constructor has pre-normalized.
nsBase
name space string for base class
return
return true if success, false if fail
Ex:
if( !_derive("MyPkg.sub.Class3","MyPkg.Class2") ) return false;
_import![]() | ||
_import= function ( ns [, nsMap [, root [, bAlone] ]] )
Let constructor create its class and map it to a name space.
ns
name space string
nsMap
name space string for mapping to.
root
the object to map into, if not set, map to the GLOBAL object/window.
bAlone
Only for M5, if set 1, the class will only be loaded in local GLOBAL/ESOE environment.
Note:
If nsMap is set to null and obj is not set, just load the ns and don't map it to a name space item.
If nsMap is not set or set to "", use the last name space item of ns as nsMap.
Ex:
_import("MyPkg.sub.Class3"); //map to window.Class3
_import("MyPkg.sub.Class3","MyClass"); //map to window.MyClass
_import("MyPkg.sub.Class3","myapp.MyClass"); //map to window.myapp.MyClass
var ns={};
_import("MyPkg.sub.Class3","",ns); //map to ns.Class3
_setpath (M2)![]() | ||
_setpath= function ( ns, path )
Set the ns path
ns
name space string
path
path name string
return
none
Ex:
_setpath("com","../lib/" );
_setpath("com.mylib","../lib2/" );
// "com.xtree.WebFXTree" will be loaded from ../lib/com/xtree/WebFXTree
// "com.mylib.class1" will be loaded from ../lib2/ mylib/class1
_loadcss (M2)![]() | ||
_loadcss= function( [_global,] ns ) _loadcss= function( [_global,] ns, css1 [, css2, ... cssN]) ) load html style sheet file from ns path Syntax 1: load default class css from [package path]/_res/[class name]/ [class name].css _global the GLOBAL object ns name space string css1...cssN css file path retive to the package path. Ex _loadcss( _global, "com.mycompany.util.myclass" ); _loadcss( window, "com.my.util", "_res/myclass/style1.css", "_res/myclass/style2.css" );
prototype._set![]() | ||
prototype._set= function( _this [, param1..., paramN] )
the initializing function of a class
_this
the 'this' object.
param1..., paramN
paremeters
ex
//_set(), use '_this' instead of 'this' in the _set() body
prototype._set= function( _this, param1, param2 )
{
//call base class _set()
if( this._base._set ) this._base._set( _this, param1?param1:0, param2?param2:0 );
//add initialization code here
}
prototype._destroy![]() | ||
prototype._destroy= function( _this )
the destroy function of a class
_this
the 'this' object.
Ex
//_destroy(), use '_this' instead of 'this' in the _destroy() body
prototype._destroy= function( _this )
{
_this= _this?_this:this;
if( !$esoe.CallBaseDestroy( this, _this ) ) return; //destroy base class
//add destruction code here
}
prototype._share![]() | ||
prototype._share= function( _global, _this )
the share initializing function of a class
_global
the GLOBAL object
_this
the 'this' object.
ex
//_share(), use '_this' instead of 'this' in the _share() body
prototype._share= function( _global, _this )
{
_this= _this?_this:this;
if( !$esoe.CallBaseShare( this, _this, _global ) ) return; //share base class
//add share code here
}