Synths
Synths is a JavaScript library that synthesize properties with type, methods, operators and more.
Development is ongoing. Test documentation is available in docs/test.md or in http://malcomwu.github.io/synths/
Usage
var synthesize = synthesize;var john = name: age: sex: weight: ;johnname'John';console; // 'John'console; // 25console; // 'male'console; // 80
Syntax
- Chainable setter
john.name('John').age(25)
- Getter
john.name()
returns'John'
- Binary operator
obj.prop('+', val)
is equivalent toobj.prop() + val
. - Assignment operator
obj.prop('+=', val)
is equivalent toobj.prop(obj.prop() + val)
. - Method of property
obj.prop('#toString')
, and aliases:obj.prop('#to string')
,obj.prop('#to-string')
, orobj.prop('#to_string')
, are equivalent toobj.prop().toString()
. - Lodash method
obj.prop('#forEach', getName)
and aliasesobj.prop('#for each', getName)
,obj.prop('#for-each', getName)
, orobj.prop('#for_each', getName)
are equivalent to_.forEach(obj.prop(), getName)
. - Property's property
obj.prop('subProp')
and aliases:obj.prop('sub prop')
,obj.prop('sub-prop')``obj.prop('sub_prop')
, are equivalent toobj.prop().subProp()
. Setterobj.prop('subProp', 123)
is equivalent toobj.prop().subProp(123)
. - Property's key,
obj.prop('key')
is equivalent toobj.prop().key
. Setterobj.prop('key', val)
is equivalent toobj.prop().key = val
. - Property's index
obj.prop(1)
, equivalent toobj.prop()[1]
.obj.prop(1, 'foo')
is equivalent toobj.prop()[1] = 'foo'
. Negative index:obj.prop(-1)
is equivalent toobj.prop(obj.prop().length -1)
.
More details can be found in the aforementioned test documentation.