Jackalope is a class extension system with an API based entirely on Moose, the post-modern class system for perl.Jackalope is written in Coffeescript, and has primarily been written with a server-side environment in mind.
Jackalope comes in two flavours: as a base class for coffeescript objects to extend from, and as set of mixins that extend your object on the fly. The
Jackalope.Class offers a base class with constructor that initializes
attributes when needed.
Jackalope.extend function mixes Jackalope features into your object. It does not mess with your constructor or any other properties of our object, but offers a factory method for constructing instead, as well as new object methods to declare attributes.
Jackalope.Class class as a base-class in Coffeescript
Jackalope = require'../lib/Jackalope'@has 'radius'isa: 'Int'required: truewriter: 'setRadius':@clearCircumference@has 'circumference'isa: 'Number'lazy_build: trueclearer: ' clearCircumference':return 2 * @diameter * MathPI# built in constructorcircle = radius: 23 ;cf = circlecircumference;circlesetRadius 90cf2 = circlecircumference;
Alternative using mixin ( also works for non-Coffeescript classes)
=# your things in constructorJackalopeextend FooFoohas 'name'isa: 'Str'required: truefoo = Foocreate name: 'Harry'
typeof === 'object'and not
typeof === 'function'
Example of the
@has 'x'isa: 'Int'required: true@has 'y'isa: 'Int'required: true@has 'start'isa: Pointrequired: true@has 'end'isa: Pointrequired: true# now do:x: 0y: 0 x: 10y: 5line = start: aend: b