Page MenuHomeGitPull.it

JX.install(new_name, new_junk)
Javelin Documentation ()

Install a class into the Javelin ("JX") namespace. The first argument is the name of the class you want to install, and the second is a map of these attributes (all of which are optional):

  • construct (function) Class constructor. If you don't provide one, one will be created for you (but it will be very boring).
  • extend (string) The name of another JX-namespaced class to extend via prototypal inheritance.
  • members (map) A map of instance methods and properties.
  • statics (map) A map of static methods and properties.
  • initialize (function) A function which will be run once, after this class has been installed.
  • properties (map) A map of properties that should have instance getters and setters automatically generated for them. The key is the property name and the value is its default value. For instance, if you provide the property "size", the installed class will have the methods "getSize()" and "setSize()". It will NOT have a property ".size" and no guarantees are made about where install is actually chosing to store the data. The motivation here is to let you cheaply define a stable interface and refine it later as necessary.
  • events (list) List of event types this class is capable of emitting.

For example:

JX.install('Dog', {
  construct : function(name) {
    this.setName(name);
  },
  members : {
    bark : function() {
      // ...
    }
  },
  properites : {
    name : null,
  }
});

This creates a new Dog class in the JX namespace:

var d = new JX.Dog();
d.bark();

Javelin classes are normal Javascript functions and generally behave in the expected way. Some properties and methods are automatically added to all classes:

  • instance.__id__ Globally unique identifier attached to each instance.
  • prototype.__class__ Reference to the class constructor.
  • constructor.__path__ List of path tokens used emit events. It is probably never useful to access this directly.
  • constructor.__readable__ Readable class name. You could use this for introspection.
  • constructor.__events__ DEV ONLY! List of events supported by this class.
  • constructor.listen() Listen to all instances of this class. See JX.Base.
  • instance.listen() Listen to one instance of this class. See JX.Base.
  • instance.invoke() Invoke an event from an instance. See JX.Base.
Parameters
stringnew_nameName of the class to install. It will appear in the JX "namespace" (e.g., JX.Pancake).
mapnew_junkMap of properties, see method documentation.
Return
void