Classify.js is a library that allows for cross browser and cross platform Object Oriented Javascript class definitions using classical inheritance patterns and namespaces behind the prototype syntax of javascript in an easy to use interface function.
Classify.js was created to simplify the creation of reusable objects in a manner much like the traditional C based languages. It is a wrapper to the Javascript prototype syntax of class object creation, instead classes are defined in object notation much similar to single instance javascript objects.
Classify.js also provides utilities methods that are useful
to javascript classes, such as auto binding methods without adding Function.bind
,
observable properties with getters, setters, and event listeners, and namespacing
that can be easily accessed and externalized.
This project is hosted on GitHub. You can report bugs and suggest new features on the issues page.
A complete Test Suite is available in the repository by running ./make.js unit
.
Classify.js is distributed under the MIT license.
Development Version (v0.10.2) | 11.91 kb, Uncompressed and Fully Commented |
---|---|
Production Version (v0.10.2) | 3.93 kb, Minified and Gzipped |
Classify()
Classify.Class
// Different ways to call Classify // Calling Classify with a string returns a namespace // @see Classify.getNamespace Classify("Vehicles") === Classify.getNamespace("Vehicles"); // Calling Classify with a string ending in a "/" returns a namespace // @see Classify.getNamespace Classify("Vehicles") === Classify.getNamespace("Vehicles"); // Calling Classify with a string separated by "/" returns a defined // class within a namespace // @see Classify.Namespace.get Classify("Vehicles/Ship") === Classify.getNamespace("Vehicles").get("Ship"); // Calling Classify with 2 string parameters returns a defined class within // a namespace // @see Classify.Namespace.get Classify("Vehicles", "Ship") === Classify.getNamespace("Vehicles").get("Ship"); // Calling Classify with first parameter as a string, and second parameter as // an object, creates a class within the namespace var Ship = Classify("Vehicles/Ship", { init : function() { } }); // Calling Classify with first parameter as a string, second parameter as a string, and // third parameter as an object, creates a class within the namespace var Ship = Classify("Vehicles", "Ship", { init : function() { } }); // The above 2 statements are the same as the following statement to create classes // @see Classify.Namespace.create var Ship = Classify.getNamespace("Vehicles").create("Ship", { init : function() { } }); // To inherit from other classes, the first parameter is the class name, second parameter // is the parent (can be from other namespaces with "Namespace/Class"), third parameter // is the descriptor var Battleship = Classify("Vehicles/Battleship", "Ship", { init : function() { } }); // The same can be achieved with the following signature var Battleship = Classify("Vehicles", "Battleship", "Ship", { init : function() { } }); // The above 2 statements are the same as the following statement to create classes // @see Classify.Namespace.create var Battleship = Classify.getNamespace("Vehicles").create("Battleship", "Ship", { init : function() { } }); // Calling Classify with objects with create classes with the object descriptor. // Using the Classify method in this manner is analogous to calling Classify.create() // Please see Classify.create for documentation // @see Classify.create var Energy = Classify({ init : function() { } }); // The above statement is the same as var Energy = Classify.create({ init : function() { } });
Classify.version
String
The version number of this file
Classify.Classify
Function
Circular reference to itself
Classify.create([parent][, implement], definition)
[parent]
{Classify.Class}
Optional first parameter defines what object to inherit from
[implement]
{Object[]}
Optional second parameter defines where to implement traits from
definition
{Object}
The description of the class to be created
Classify.Class
Classify.getNamespace(namespace)
namespace
{String}
Dot separated namespace string
Classify.Namespace
Classify.destroyNamespace(namespace)
namespace
{String}
Dot separated namespace string
Classify.testNamespace(namespace)
namespace
{String}
Dot separated namespace string
Classify.Namespace
Classify.getGlobalNamespace()
Classify.Namespace
Classify.global
Classify.Namespace
The globally named namespace
Classify.addMutator(name, mutator[, mutator.onCreate][, mutator.onPropAdd][, mutator.onPropRemove][, mutator.onInit])
name
{String}
The name of the mutator reference to add
mutator
{Object}
The mutator definition with optional hooks
[mutator.onCreate]
{Function}
The hook to be called when a class is defined
[mutator.onPropAdd]
{Function}
The hook to be called when a property with the __name_ prefix is added
[mutator.onPropRemove]
{Function}
The hook to be called when a property with the __name_ prefix is removed
[mutator.onInit]
{Function}
The hook to be called during each object's initialization
Classify.removeMutator(name)
name
{String}
The name of the mutator to be removed
Classify.extend(base, args)
base
{Object}
The base object to copy properties into
args
{Object[]}
Set of objects to copy properties from
Object
Classify.provide(namespace, base)
namespace
{String}
The dot separated namespace tree to create
base
{Object}
The object to create the namespace tree within
Object
Classify.noConflict()
Classify
(function(Classify) { // here you can use the Classify object and remove the global reference to it // this function is only available on browser environments })(Classify.noConflict());
Classify.Class()
Classify.Class.superclass
Classify.Class
Reference to the parent that this object extends from
Classify.Class.subclass
Array
Array containing a reference to all the children that inherit from this object
Classify.Class.implement
Array
Array containing all the objects and classes that this object implements methods and properties from
Classify.Class.bindings
Array
Array containing the list of all the bound properties that is wrapped during object initialization
Classify.Class.observables
Object
Hashtable containing the definitions of all the observable properties that is implemented by this object
Classify.Class.__isclass_
Boolean
Flag to determine if this object is created by Classify.create
Classify.Class.invoke()
Classify.Class
Classify.Class.applicate(args)
args
{Array}
Array of arguments to construct the object with
Classify.Class
Classify.Class.extend([implement], definition)
[implement]
{Object[]}
Optional parameter defines where to implement traits from
definition
{Object}
The description of the class to be created
Classify.Class
Classify.Class.addProperty(name[, property][, prefix=""])
name
{String|Object}
The property name to add or if object is passed in then it will iterate through it to add properties
[property]
{Object}
The property to add to the class
[prefix=""]
{String}
Prefix of the property name if any
Classify.Class
Classify.Class.removeProperty(name)
name
{String}
The name of the property to remove
Classify.Class
Classify.Class.addStaticProperty(name, property)
name
{String}
The name of the property to add
property
{Object}
The property to store into the object's base
Classify.Class
Classify.Class.removeStaticProperty(name)
name
{String}
The name of the property to remove
Classify.Class
Classify.Class.addBoundProperty(name, property)
name
{String}
The name of the property to add
property
{Function}
The property to always bind the object's context with
Classify.Class
Classify.Class.removeBoundProperty(name)
name
{String}
The name of the property to remove
Classify.Class
Classify.Class.addObservableProperty(name, property)
name
{String}
The name of the observable property to add
property
{Object}
The descriptor of the observable property
Classify.Class
Classify.Class.removeObservableProperty(name)
name
{String}
The name of the observable property to remove
Classify.Class
Classify.Class.addAliasedProperty(name, property)
name
{String}
The name of the alias for the new property
property
{String}
The name of the property alias
Classify.Class
Classify.Class.addUnwrappedProperty(name, property)
name
{String}
The name of the new property
property
{String}
The name of the property to add
Classify.Class
Classify.Class.prototype
Object
Prototype chain for Classify.Class
Classify.Class.prototype.constructor
Classify.Class
Reference to the constructor function of this object
Classify.Class.prototype.self
Classify.Class
Reference to the constructor function of this object
Classify.Class.prototype.init()
Classify.Class
Classify.Class.prototype.parent()
Object
Classify.Class.prototype.extend([implement], definition)
[implement]
{Object[]}
Optional parameter defines where to implement traits from
definition
{Object}
The description of the class to be created
Classify.Class
Classify.Class.prototype.invoke(name, args)
name
{Object}
The name of the parent method to invoke
args
{Array}
The arguments to pass through to invoke
Object
Classify.Namespace(name)
Classify.Class
name
{String}
The name of the namespace to construct with
Classify.Namespace.prototype
Classify.Class
Prototype chain for Classify.Namespace
Classify.Namespace.prototype.name
String
The name of the namespace
Classify.Namespace.prototype.ref
Object
Hashtable containing references to all the classes created within this namespace
Classify.Namespace.prototype.create(name[, parent][, implement], definition)
name
{String}
The name of the created class within the namespace
[parent]
{String|Classify.Class}
Optional second parameter defines what object to inherit from, can be a string referencing a class within any namespace
[implement]
{Object[]}
Optional third parameter defines where to implement traits from
definition
{Object}
The description of the class to be created
Classify.Class
Classify.Namespace.prototype.destroy(classname)
classname
{String}
Name of class to remove from this namespace
Classify.Namespace
Classify.Namespace.prototype.exists(classname)
classname
{String}
Name of class to check if it has already been defined
Boolean
Classify.Namespace.prototype.get(name)
name
{String}
The name of the class to retrieve
Classify.Namespace.prototype.load(name)
name
{String}
The name of the class to load
Classify.Namespace
Classify.Namespace.prototype.setAutoloader(callback)
callback
{Function}
The function to call when a class that doesn't exist needs to be loaded
Classify.Namespace
Classify.Namespace.prototype.getName()
Classify.Namespace.prototype.toString()
Classify.Observer(value, value.value[, value.writable=true][, value.delay=0][, value.getter][, value.setter])
Classify.Class
value
{Object}
The internal value can be either an object or a value
value.value
{Object}
The internal value if the parameter was passed in as an object
[value.writable=true]
{Boolean}
Marks this object as writable or readonly
[value.delay=0]
{Number}
Only fire the event emitter after a delay of value.delay ms
[value.getter]
{Function}
The internal get modifier
[value.setter]
{Function}
The internal set modifier
Classify.Observer.prototype
Classify.Class
Prototype chain for Classify.Observer
Classify.Observer.prototype.context
Classify.Class
The context that this object is created within
Classify.Observer.prototype.name
String
The name of the property that this object observes
Classify.Observer.prototype.writable
Boolean
Flag to check if this property is writable
Classify.Observer.prototype.delay
Number
Number of seconds to delay the event emitter, 0 will disable delays
Classify.Observer.prototype._debounce
Number
Flag to hold the delay timer
Classify.Observer.prototype.value
Object
The internal value of this object
Classify.Observer.prototype.events
Array
Array containing all the event listeners for when this value changes
Classify.Observer.prototype.getter(value)
value
{Object}
The internal value of this object
Object
Classify.Observer.prototype.setter(value, original)
value
{Object}
The new value that will be set
original
{Object}
The original internal value of this object
Object
Classify.Observer.prototype.get()
Object
Classify.Observer.prototype.set(value)
value
{Object}
Mixed value to store internally
Classify.Class
Classify.Observer.prototype.emit()
Classify.Class
Classify.Observer.prototype._triggerEmit(args)
args
{Array}
Array of arguments to pass to the bound event listeners
Classify.Observer.prototype.addListener(listener)
listener
{Function}
The event listener to add
Classify.Class
Classify.Observer.prototype.on(listener)
listener
{Function}
The event listener to add
Classify.Class
Classify.Observer.prototype.once(listener)
listener
{Function}
The event listener to add
Classify.Class
Classify.Observer.prototype.removeListener(listener)
listener
{Function}
The event listener to remove
Classify.Class
Classify.Observer.prototype.removeAllListeners()
Classify.Class
Classify.Observer.prototype.listeners()
Array
Classify.Observer.prototype.toValue()
Boolean|Number|String
Classify.Observer.prototype.toString()
String