English | 简体中文 XML | HTML | | |
ESOE 首页
文档

Javascript 实现使用说明书

This article describes an implementation for ESOE V0.2, in javascript language.

版权声明
ESOE Version: 0.2
Version : 0.3

Feng WeiGuo
forxm@21cn.com
http://www.viviasoft.com

2006-8
Conventions
nsname space string, ex. "MyPkg.sub.Class3"
nsxname space string or a constructor/function
funcabbr. function/constructor
pkgabbr. package
namea String object
Modules
ESOE of current version includes 6 modules.
FilemoduleFeatureDescription
esoe.jsM1 : kernel1. 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.jsM2 : resource1. Physcal mapping of name space.
2. Resource loading.
esoe3.jsM3 : loader1. Automatically classes loading.1. M3 depend on M2.
_update.jsUpdate tool for M3
esoe4.jsM4 : destroy1. Destroy mechanism1. A temprorary module.
2. M4 may be related to all other modules.
esoe5.jsM5 : share1. Class sharing
2. Share the ESOE itself
ESOE布局
链接节点: [ESOE 技术说明书 0.2] > [ESOE引擎] > [ESOE布局]
ESOE Parameters
ESOE object has below properties that can be loaded from external.
srcESOE engine M1 file
moduleString 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
debugDebug level parameter, current version support bellow value,
0: no debug (deault)
1: the lowest debug level
9: the highest debug level
nokeyc2 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
Keywords
_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);
_package
same as _ns()
_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;
_derivex
_derivex= function ( ns, nsBase1 [, ... nsBaseN] )

copy the properties of multiple base classes.

ns
	name space string
nsBase1...nsBaseN
	name space string for base classes

return
	none

Ex:
	_derivex( "com.my.util.myclass", "com.my.util.class1", "com.my.util.class2" );
_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
_getpath (M2)
_getpath= function ( ns [, subpath] )

Get the ns path

ns
	name space string
subpath
	the sub path that to be appended to the reault path

return
	the result path

Ex
	_getpath("com.mylib.myclass");
	_getpath("com.mylib.myclass","myss.css");
_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" );
_update (M3)
_update= function()

If package loading need recursive process, call this to active it.

Note:
_update must be at the last place of a <script> tag enclosure.

Ex:
	<script>
	...
	_update();
	</script>
_base Property
_base property is the prototype of the base class.

An esoe class/constructor or its instance can use _base to get the base class property.

Ex:
	alert( obj1._base.p1 );
	obj1._base.func1();
	obj1._base.func1.call(obj1);
_pkg Property
_pkg property is the nearest upper package name space item.

An esoe constructor or its instance can use _pkg to get the reference to its nearest upper package name space item.

Ex:
	var a=new this._pkg.Class5;
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
	}
Tools
$esoe.Track
$esoe.Track= function ( [obj] )

record shared ESOE object for later use, or track class instance for destroy mechanism.

obj
	the class instance object to track. If omit, tack the ESOE object
$esoe.TRACE
$esoe.TRACE= function( s )

record debug string to $esoe._trace Array

s
	debug string
$esoe.ALERT
$esoe.ALERT= function( s )

alert a debug information

s
	debug alert string
$esoe.ClearTrace
$esoe.ClearTrace= function()

clear the debug buffer $esoe._trace
$esoe.Destroy
$esoe.Destroy= function()

active ESOE's destroy mechanism

ex
	window.onunload= function()
	{
		if( $esoe ) $esoe.Destroy();
	}
$esoe.DestroyObject
$esoe.DestroyObject= function( obj )

call the _destroy function of an object

obj
	the object
$esoe.RemoveProperty
$esoe.RemoveProperty= function( obj, i [, bDestroy ])

remove the property of an object

obj
	the object
i
	the name of the property
bDestroy
	if call the _destroy of the property
$esoe.Share
$esoe.Share= function( _global [, bAlone] )

share a ESOE object

_global
	the GLOBAL object of current environment.
bAlone
	set 1 if all class should be loaded only in current environment.

* All Rights Reserved * 版权所有 * 2000-2006 * www.viviasoft.com * Powered by supertree & xforum *

粤ICP备06042644号