extend
void
extend
(
source
,
extensions
)
extend takes a source argument which is the object to be extended, and at least one extension argument.
If the extension argument is an Object then the properties of the extension are copied to the source argument.
If the extension argument is a Function then the the function is called and the source is extended with the
return value of the function. If the extension argument is an Array or there are more than one extension
arguments, the source is extended with each of the elements in the array.
- Parameters:
-
source <object>the object to be extended -
extensions <object* or Array>
- Returns:
void
namespace
Object
namespace
(
name
,
extensions
)
namespace creates a new global namespace object.
It takes a namespace argument which is a dot separated string containing the name of the namespace to be created eg.
Utils.namespace("some.name.space").
If the named global object or any of the objects in the chain are not defined, it will create an empty object with
that name i.e. if no objects are defined the above code is equivalent to
var some = {};
some.name = {};
some.name.space = {};
Any additional arguments are passed to Utils.extend which is called with the namespace object as the source.
- Parameters:
-
name <String>A dot separated namespace name eg. 'Utils.some.namespace' -
extensions <Object*>An object containing attributes to be added to the namespace.
- Returns:
Object - the namespace object
replaceNamespace
Object
replaceNamespace
(
name
,
extensions
)
replaceNamespace is a destructive version of namespace. replaceNamespace will replace the namespace
object (but not it's predecessors in the chain) if it is already defined. replaceNamespace also records
the original value of the namespace object, so that it can be recovered with revertNamespace.
- Parameters:
-
name <String>A dot separated namespace name eg. 'Utils.some.namespace' -
extensions <Object*>An object containing attributes to be added to the namespace.
- Returns:
Object - the namespace object
revertNamespace
Object
revertNamespace
(
name
)
revertNamespace allows the namespace to be renamed in case of conflict. This method only works if the
namespace was initially created with replaceNamespace.
var NewNamespace = Utils.revertNamespace("SomeNamespace")
- Parameters:
-
name <String>A dot separated namespace name eg. 'Utils.some.namespace'
- Returns:
Object - the namespace object