JavascriptObjectTemplates
Templates for Javascript Objects
How to use?
Create a template using a layout object describing the type and default value. If the default value is null, then the field can be of any type.
var JOT = ; // Create new templatevar template = myString: 'myStringValue' myNumber: 1234 multipleValues: null subObject: subNumber: 5678 ;
Note: This will be foundation for all following examples.
get(selector)
Get a value from the template.
template; // 'myStringValue'template; // 1234template; // 5678
set(selector, value)
Set a value to the template.
Note: Only accepts same type unless it's default value was null.
template; // truetemplate; // 'myNewStringValue' template; // false (because the type is different)template; // 'myNewStringValue' template; // false (because the field isn't defined in layout)
merge(object)
Set multiple values from an object.
template; // 'myStringValue'template; // 1234 template; template; // 'myObjectStringValue'template; // 1234 (because the type is different)template; // undefined (because the field isn't defined in layout)template; // 0
getObject()
Get the template as object.
Can be used together with reset()
to allow the template to be used multiple times.
template;template; // false (because the type is different) template;/*{ myString: 'myNewStringValue', myNumber: 5678 multipleValues: null, subObject: { subNumber: 5678 }}*/
reset()
Resets the template back to default values.
Can be used together with getObject()
to allow the template to be used multiple times.
template;template; // false (because the type is different) template;/*{ myString: 'myNewStringValue', myNumber: 5678 multipleValues: null, subObject: { subNumber: 5678 }}*/ template; template;/*{ myString: 'myStringValue', myNumber: 1234 multipleValues: null, subObject: { subNumber: 5678 }}*/