Troop
Full-featured, testable OOP
Wiki
Reference
Troop features
- multiple inheritance with traits
- makes use of ES5 property attributes
- pseudo-privates are non-enumerable
- constants are actually read-only
- testing mode for applying mock methods
- postponed, on-demand property definitions
- delegation of instantiation with surrogates
- support for instance memoization
Troop is distinguished from other OOP-related libs such as MooTools or Backbone by
- not littering your classes and instances with its own meta-properties
- non-declarative API leads to better IDE integration
- offering simpler unit testing with built-in mocks to speed up TDD process
Example
var MyClass = troop.Base.extend()
.addPrivate({
_secret: "ufo" // static private property
})
.addPublic({
hello: "world" // static public property
})
.addConstants({
pi: 3.14 // static public constant
})
.addMethods({
init: function (who) {
this.addPublic({
hello: who
});
}
});
var myInstance = MyClass.create("all");
Check out these jsFiddles for more examples: