Extend Class (declaration )Classes are created using extend by giving a dictionary that contains the following keys:
name, an optional name for this class parent, with a reference to a parent class (created with Extend) initialize, with a function to be used as a constructor properties, with a dictionary of instance attributes methods, with a dictionary of instance methods shared, with a dictionary of class attributes operations, with a dictionary of class operationsInvoking the Class function will return you a Class Object that implements the following API:
isClass() returns true( (because this is an object, not a class) getName() returns the class name, as a string getParent() returns a reference to the parent class getOperation(n) returns the operation with the given name hasInstance(o) tells if the given object is an instance of this class isSubclassOf(c) tells if the given class is a subclass of this class listMethods() returns a dictionary of methods available for this class listOperations() returns a dictionary of operations (class methods) listShared() returns a dictionary of class attributes listProperties() returns a dictionary of instance attributes bindMethod(o,n) binds the method with the given name to the given object proxyWithState(o) returns a proxy that will use the given object as if it was an instance of this class (useful for implementing super)When you instanciate your class, objects will have the following methods available:
isClass() returns true( (because this is an object, not a class) getClass() returns the class of this instance getMethod(n) returns the bound method which name is n getCallback(n) the equivalent of getMethod, but will give the this as additional last arguments (useful when you the invoker changes the this, which happens in event handlers) isInstance(c) tells if this object is an instance of the given classUsing the Class function is very easy (in Sugar):
var MyClass = Extend Class {
name:"MyClass"
initialize:{
self message = "Hello, world !"
}
methods:{
helloWorld:{print (message)}
}
}instanciating the class is very easy too
var my_instance = new MyClass()
Extend Protocol (pdata )Extend Singleton (sdata )Extend getChildrenOf (aClass:Class )Extend getClass (name )Extend getClasses ( )This module implements a complete OOP layer for JavaScript that makes it easy to develop highly structured JavaScript applications.
Classes are created using extend by giving a dictionary that contains the following keys:
name, an optional name for this class parent, with a reference to a parent class (created with Extend) initialize, with a function to be used as a constructor properties, with a dictionary of instance attributes methods, with a dictionary of instance methods shared, with a dictionary of class attributes operations, with a dictionary of class operationsExtend 2.0 is a rewritten, simplified version of the Extend 1 library. It is not compatible with the previous versions, but the API will be stable from this release.
You can get more information at the Extend project page.