Namespace: troop

troop

Source:

Classes

Base
Feature
Properties

Members

<static> messy :boolean

When true, all properties are writable, so they can be modified through assignment.
Source:

<static> privatePrefix :string

Prefix applied to names of private properties and methods.
Source:

<static> testing :boolean

Whether Troop is in testing mode (application state)
Source:

<static> writable :boolean

Whether methods should be writable (environmental)
Source:

Methods

<static> amendPostponed(host, propertyName, modifier)

Applies a modifier to the postponed property to be called AFTER the property is resolved. Amendments are resolved in the order they were applied. Amendments should not expect other amendments to be applied.
Parameters:
Name Type Description
host object Host object.
propertyName string Property name.
modifier function Amends property value. Arguments: host object, property name, plus all extra arguments passed to .amendPostponed(). Return value is discarded.
Source:
Example
var ns = {};
troop.postpone(ns, 'foo', function () {
 ns.foo = {hello: "World"};
});
//...
troop.amendPostponed(ns, 'foo', function () {
 ns.foo.howdy = "Fellas";
});
// howdy is not added until first access to `ns.foo`

<static> postpone(host, propertyName, generator)

Postpones a property definition on the specified object until first access. Initially assigns a special getter to the property, then, when the property is accessed for the first time, the property is assigned the return value of the generator function, unless a value has been assigned from within the generator.
Parameters:
Name Type Description
host object Host object.
propertyName string Property name.
generator function Generates (and returns) property value. Arguments: host object, property name, plus all extra arguments passed to .postpone().
Source:
Example
var obj = {};
troop.postpone(obj, 'foo', function () {
   return "bar";
});
obj.foo // runs generator and alerts "bar"