Class Index | File Index

Classes


Class $interface

This class encapsulates information about an interface, but its constructor is used as a function (without the "new" keyword) to create an interface. It is used as a constructor for private implementation purposes only.
Defined in: class-debug.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
$interface(name, descriptor)

Creates an interface with the specified name and properties.

Method Summary
Method Attributes Method Name and Description
 

Applies this interface to the specified object or class.

 
Gets a list of all methods in this interface (including methods of inherited interfaces).
 
Gets the name of the interface.
 
hasMethod(methodName)
Tests if the interface (or any inherited interfaces) contains a method.
 
Overridden to return a string that identifies this $interface.
 

Creates an anonymous implementation of this interface whose methods are all implemented by simply calling the method of the name on the specified object.

Class Detail
$interface(name, descriptor)

Creates an interface with the specified name and properties. Note that this documentation describes the behavior of $interface when used as a method (without the "new" keyword). This should only be called as a method rather than as a constructor. Instances of $interface are created as a private implementation detail of $interface being called as a method.

An interface describes methods that must be implemented by a class that claims to implement the interface. Interfaces can also extend other interfaces and contain static properties/methods. See $interface.descriptor for details.

Parameters:
{String} name
The name of the interface. The name may describe a path of multiple nested namespace/class/object names separated by a period (.). The entire path to the interface name is expected to exist already. See $namespace for details about creating namespaces.
{$interface.descriptor} descriptor
An object containing the properties of the interface, which can describe methods, static methods, static properties, and more.
Returns:
{$interface} The newly created interface.
Method Detail: applyInterface
{$class|Function|Object} applyInterface(obj)

Applies this interface to the specified object or class. This marks the object or class as implementing this interface. The debug version of the $class library will verify that all interface methods are actually implemented by the object or class.

This method has two intended uses:

  1. Retroactively mark a class as implementing an interface. This allows you to avoid modifying the definition of a class. You can pass either the constructor of the class, or the class's $class object to applyInterface. Interfaces can be applied to classes that are not within the $class framework by applying the interface to the class's constructor, but requires that all interface methods are implemented on the class's prototype rather than assigned directly to properties in the constructor. The interface information will be preserved if the class is later adapted into the $class framework via $class.adapt.
  2. Mark a specific object as implementing an interface. This could be an anonymous object, which would be like creating an anonymous implementation of the interface. IMPORTANT: Interfaces cannot be applied to directly to functions. Doing so will be interpreted as an attempt to apply the interface to a class that is not within the $class framework (see above).

When used to apply an interface to an object (not a class), be aware that a property (_$class_interfaces) will be added to the object. If the object cannot be polluted with an extra property, then use #wrapObject.

Debug version errors:

Parameters:
{$class|Function|Object} obj
The constructor or $class object of a class that implements all methods of this interface (to apply the interface to a class), or any object that implements all methods of this interface to apply the interface to that particular object.
Returns:
{$class|Function|Object} The obj argument.
Method Detail: getMethods
{String[]} getMethods()
Gets a list of all methods in this interface (including methods of inherited interfaces).
Returns:
{String[]} an array of method names.
Method Detail: getName
{String} getName()
Gets the name of the interface.
Returns:
{String} the full name of the interface.
Method Detail: hasMethod
{Boolean} hasMethod(methodName)
Tests if the interface (or any inherited interfaces) contains a method.
Parameters:
{String} methodName
the name of a potential method.
Returns:
{Boolean} true if this interface has a method with the specified name.
Method Detail: toString
{String} toString()
Overridden to return a string that identifies this $interface.
Returns:
{String} a string in the form "[$interface _name_]", where _name_ is the full name of this interface.
Method Detail: wrapObject
{Object} wrapObject(obj)

Creates an anonymous implementation of this interface whose methods are all implemented by simply calling the method of the name on the specified object. This may be an alternative to applying the interface directly to the object, which will add a property to the object that may be undesirable 9see #applyInterface. The debug version of the $class library will verify that the object implements all methods of this interface.

Parameters:
{Object} obj
An object that implements all methods of this interface.
Returns:
{Object} a new object that implements this interface by calling methods on the obj argument.

Documentation generated by JsDoc Toolkit 2.3.2 on Sat Nov 13 2010 01:18:48 GMT-0500 (EST)