module.coffee | |
---|---|
_ = require 'underscore' | |
Copy into object all properties from module
@objects {Objects...} the objects to extend with @api public | extend = (objects...) ->
for object in objects
for own name, property of object
@[name] = property |
Copy into object all properties from module onto the prototype
@objects {Objects...} the objects to mix in @api public | include = (objects...) ->
proto = @::
for object in objects
for own name, property of object
proto[name] = property |
The same as "include" only it does not copy the properties, it achieves augmentation by injecting copies of module-objects into the receiver's prototype chain @objects {Objects...} the objects to mix in @api public | includeInter = (objects...) ->
for object in objects
module = _.clone(object)
previousPrototype = @::
@:: = module
module.__proto__ = previousPrototype |
make sure to preserve the constructor property | @::constructor = previousPrototype.constructor if previousPrototype.hasOwnProperty 'constructor'
exports.extend = extend
exports.include = include
exports.includeInter = includeInter
|