Precursor
Precursor
is the JavaScript that could have been.
Usage
Let's start with an example. We'll create a function that draws a circle on a canvas.
var Draw = Precursorclone; Draw; Draw;
Mutating Methods
Precursor.def( fn )
Precursor.getter( fn )
Precursor.lazy( fn )
Precursor.flag( name, properties )
Cloning Methods
Precursor.with()
Precursor.clone
Precursor.tap()
Precursor.promise()
Precursor.then()
Precursor.catch()
#def( namedFunction )
def
is used to assign non-enumerable functions.
Values can be assigned with #def( name, value )
.
#getter( namedFunction )
Similar to def
except getters are called without parenthesis:
var Invoice = Precursorclone; Invoice; var invoice = Invoice invoiceisDue === false;
#lazy( namedFunction )
lazy
is just like getter
, but it re-assigns itself
as the return value of the passed function.
#with( attributes )
Create a clone with the passed attributes appended:
var person = Precursor;
#flag( name, attributes )
flag
is a shortcut for creating a getter that returns a clone with attributes appended:
var Order = Precursorclone; Order;Order; var order1 = OrderasShipped;var order2 = order1asDelivered; order1status === 'shipped';order2status === 'delivered';
#clone
#tap( fn )
tap
creates a clone, applies fn
to it, and then returns it.
The clone is also passed as the first argument.
Precursor;
#promise( fn )
Precursor
promises require an ES6-compatible window.Promise
object.
Alternatively, you can set your own: Precursor.def('Promise', RSVP.Promise)
.
Precursor
promises are lazy: fn
isn't invoked until #then()
has been called on a clone.