classloader.js


file classloader.js

Class Summary
jGrouse ClassLoader is responsible for loading all modules, classes and resources.
Class implementing jGrouse module - a piece of code that could be loaded dynamically

Interface Summary
Structure describing a class

Function Summary
private create()
Declare class for jGrouse framework Not to be used directly
define(String subclassName, String superclassName, function(embed) body)
define(Object obj)
Define class.
forEach(Array arr, arrayIteratorCallback func, [Boolean backwards])
forEach(Object obj, objectIteratorCallback func)
Execute a function for each element of array or member of structure
String fullUrl(String url)
Converts given URL to full one.
getImportString(String utilName)
Get a string that could be eval'ed in order to bring into current namespace properties of given object.
Factory function for XMLHttpRequest objects
module(String name, String[] requires, String[] imports, function(embed) body, function(embed) postInit)
module(Object obj)
Define module.
require(String module, function() callback)
require(String[] modules, function() callback)
Loads one or several modules and invokes callback once module is loaded and initialized
resolveName(String name)
Returns object corresponding to given name
Standard constructor used by JGrouse framework.

Function Interface Summary
arrayIteratorCallback(Object value, [int index])
Signature of function that could be used for iterating over arrays/collections
objectIteratorCallback(Object value, [Object key])
Signature of function that could be used for iterating over object or map properties

Function Details

function create

private create()
Declare class for jGrouse framework Not to be used directly
Defined in classloader.js

function define

define(String subclassName, String superclassName, function(embed) body)
define(Object obj)
Define class. If class is defined inside a module, actual definition would be deferred until all classes in the module are declared.
Example 1:
jgrouse.define('mySubclass', 'mySuperclass', function(sugar) { eval(sugar); function myPrivateMember(arg) { // do some magic } return { // note that the curly bracket should be // on the same line as return keyword initialize : function(arg1, arg2) { _super(this, 'initialize', arguments) }, methodOne : function(arg1, arg2) { var privateResult = myPrivateMember.call(this, arg2); return _super(this, 'methodOne', [arg1]) + privateResult; } } });
Example 2:
jgrouse.define({ subclassName : 'mySubclass', superclassName : 'mySuperclass', properties : function(sugar) { eval(sugar); return { .... } } });
Parameters:
Option 1
subclassName - name of new class
superclassName - name of super class for the new class. If super class does not exist, pass null
body - function that returns structure with members of class.
Option 2
obj - structure containing object's parameters:
  • String subclassName - name of new class
  • String superclassName - name of super class for the new class. If super class does not exist, pass null
  • function(embed) body - function that returns structure with members of class
Defined in classloader.js

function forEach

forEach(Array arr, arrayIteratorCallback func, [Boolean backwards])
forEach(Object obj, objectIteratorCallback func)
Execute a function for each element of array or member of structure
Parameters:
Syntax 1 - array based (iteration over array elements)
arr - array to be iterated
func - function to be called for each array element.
[backwards] - if iteration should start from the end of the array. Default value is "false". Iteration from the end of the array could be useful when iterator function removes elements from the array
Syntax 2 - object based (iteration over object properties)
obj - source object
func - function to be called for each object property.
Defined in classloader.js

function fullUrl

String fullUrl(String url)
Converts given URL to full one. If URL is relative, then it is converted to absolute, using current window's location
Parameters:
url - url to convert
Returns:
absolute url
Defined in classloader.js

function getImportString

getImportString(String utilName)
Get a string that could be eval'ed in order to bring into current namespace properties of given object. If the argument passed is in the form of
foo.bar.Bla
then the resulting string would be
var Bla = foo.bar.Bla
If the last part of argument is *, then all properties that are found are imported. For example, if com.bar.util has properties propOne and propTwo, then
jgrouse.getImportString('com.bar.util.*')
would result in
var propOne = com.bar.util.propOne; var propTwo = com.bar.util.propTwo
Parameters:
utilName - name of utility or class to be imported
Defined in classloader.js

function getTransport

getTransport()
Factory function for XMLHttpRequest objects
Defined in classloader.js

function module

module(String name, String[] requires, String[] imports, function(embed) body, function(embed) postInit)
module(Object obj)
Define module. Module is a container of classes and utility functions that are related to each other. Example 1:
jgrouse.module( { moduleName : 'myModule', requires : ['moduleOne', 'moduleTwo'], imports : ['com.foo.Bar', 'com.foo.Brick'], body : function(sugar) { eval(sugar); // module body follows }, postInit : function(sugar) { eval(sugar); ... } });
Example 2:
jgrouse.module( 'myModule', ['moduleOne', 'moduleTwo'], ['com.foo.Bar', 'com.foo.Brick'], function(sugar) { eval(sugar); // module body follows }, function(sugar) { eval(sugar); // post init code ... } );
Parameters:
Option 1
name - name of the module
requires - array of strings containing names of modules that are used by this module, optional
imports - array of strings containing names of classes that should be imported into module's namespace
body - function containing body of module. Called when all the required modules are loaded
postInit - function that is called after module is initialized. Called after initialization of module (optional)
Option 2
obj - structure containing the module parameters
  • String name - name of the module
  • String[] requires - array of strings containing names of modules that are used by this module, optional
  • String[] imports - array of strings containing names of classes that should be imported into module's namespace
  • function(embed) body - function containing body of module. Called when all the required modules are loaded
  • function(embed) postInit - function that is called after module is initialized. Called after initialization of module (optional)
Defined in classloader.js

function require

require(String module, function() callback)
require(String[] modules, function() callback)
Loads one or several modules and invokes callback once module is loaded and initialized
Parameters:
Load one module
module - name of module to be loaded
callback - function to be invoked after module is initialized
Load several modules
modules - array with names of modules to be loaded
callback - function to be invoked after module is initialized
Defined in classloader.js

function resolveName

resolveName(String name)
Returns object corresponding to given name
Parameters:
name - name of object to be resolved
Returns:
either found object or null if it was not found
Defined in classloader.js

function standardConstructor

private standardConstructor()
Standard constructor used by JGrouse framework. Not to be used directly
Defined in classloader.js

Function Interface Details

ifunction arrayIteratorCallback

arrayIteratorCallback(Object value, [int index])
Signature of function that could be used for iterating over arrays/collections
Parameters:
value - current value
[index] - current index in array/collection
Defined in classloader.js

ifunction objectIteratorCallback

objectIteratorCallback(Object value, [Object key])
Signature of function that could be used for iterating over object or map properties
Parameters:
value - current value
[key] - current key/name of property
Defined in classloader.js