boo
The boo module provides primitives that abstract the semantics of prototypical object orientation, as implemented by JavaScript, such that these features can be explored with a more usable interface.
The module provides such features as the stand-alone functions: extend
and derive
, as well as an Object interface that can be extended upon: Base
.
DataObject
type DataObject :: { "to_data" :: () -> Object }
Mixin
type Mixin :: Object | DataObject
copy_property(source, target, property)
copy_property! :: Object, target:Object*, String -> target
Copies a property from source
to target
.
.. function:: data_obj_p(subject)
data_obj? :: Any -> BoolChecks if the given subject matches the
DataObject
interface.
.. function:: resolve_mixin(object)
resolve_mixin :: Object -> ObjectReturns the proper mixin for the given
object
.
.. function:: fast_extend(object, mixins)
fast_extend! :: target:Object*, [Mixin] -> targetExtends the target object with the provided mixins, using a right-most precedence rule — when there's a property conflict, the property defined in the last object wins.
DataObject
instances are properly handled by theresolve_mixin
function.
extend(target, mixins...)
extend!:: Object*, Mixin... -> Object
Extends the target object with the provided mixins
, using a right-most precedence rule.
detail-link
+ <extend>
merge(mixins...)
merge :: Mixin... -> Object
Creates a new object that merges the provided mixins
, using a right-most precedence rule.
detail-link
+ <merge>
derive(prototype, mixins...)
derive :: Object, Mixin... -> Object
Creates a new object inheriting from the given prototype
and extends the new instance with the provided mixins
.
detail-link
+ <derive>
object Base :: { init! :: @this:Object*, Any... -> this
make :: @this:Object, Any... -> Object <| this
derive :: @this:Object, Any... -> Object <| this
}
The root object for basing all the OOP code. Provides all of Boo's primitive combinators in an easy and extensible OOP-way.
detail-link
+ <base>
-- Interface
type DataObject :: { "to_data" :: () -> Object }
type Mixin :: Object | DataObject
-- Internal
copy_property! :: Object, target:Object*, String -> target
data_obj? :: Any -> Bool
resolve_mixin :: Object -> Object
fast_extend! :: target:Object*, [Mixin] -> target
-- Public
extend! :: Object*, Mixin... -> Object
merge :: Mixin... -> Object
derive :: Object, Mixin... -> Object
object Base :: { init! :: @this:Object*, Any... -> this
make :: @this:Object, Any... -> Object <| this
derive :: @this:Object, Any... -> Object <| this
}
extend merge derive base