obj
A very tiny library that turns Object.create()
into a method called clone
,
where the idea is to use a simple system of cloning and mixing prototypes:
Obj.clone()
var Fruit = ObjFruittaste = 'sweet'Fruit {return 'it tasted ' + thistaste} var Apple = FruitAppletexture = 'crunchy'Apple { return Fruiteat + ' and ' + thistexture } Appletaste === 'sweet' // trueApple // 'it tasted sweet and crunchy'
Obj.init()
init
acts as a constructor for cloned objects. It is run when clone
is called using any arguments passed to clone
. For example, you may want a new object insantiated each time the original object is cloned:
var Original = ObjOriginal { thisnew_obj = key: param } var MyClone = Original Originalnew_obj //undefinedMyClonenew_obj //{key: 'my value!'}
Obj.mixin()
There's also a mixin
method, allowing you to mix another object's properties
into your own object. It will override existing
defined properties.
var Edible = ObjEdible {return 'it tasted ' + thistaste} var Kale = ObjKaletaste = 'bitter'Kale Kale // 'it tasted bitter'
installation
npm install the-swerve/obj
compatibility
ie6+
A polyfill is provided for browsers that don't have Object.create
defined.