ClassFactory
Summary
A Factory for creating Class constructors.
Allows for "soft" binding arguments to the Class constructor; bound arguments will serve as the default constructor arguments, but any arguments passed in on instantiation will override the bound arguments.
For example: var Klass = new ClassFactory(ParentKlass, ['a', 'b', 'c']); new Klass('x'); // ParentKlass ctor called with ('x', 'b', 'c')
This can be useful for wiring up Classes which are simply configured versions of a parent class. For example,
var DefaultSelectedModel = new ClassFactory(aeris.Model, selected: true); var model = new DefaultSelectedModel();
model.get('selected') // true
// Argument binding is "soft" var notSelectedModel = new DefaultSelectedModel(selected: false); notSelectedModel.get('selected') // false
Use the extendArgObjects option to extend instance argument objects.
For example:
var SomeModelClass = new ClassFactory(Model, [foo: 39;bar39;, hello: 39;World39;], extendArgObjects: ...];
var model = new SomeModelClass(hello: 39;Universe39;);
// with extendArgObjects: true // called attrs extend the bound attrs model.toJSON() === foo: 39;bar39;, hello: 39;Universe39;);
// with extendArgObjects: false // called attrs replace the bound attrs model.toJSON === hello: 39;Universe39;
Constructor
Item Index
Methods
Methods
parseObjectValues
Syntax
Summary
Parse end-leaf values of deep nested objects, replacing string'ed objects to their primitive values.
Useful for processing inputs that are serialized only as strings (eg. forms, querystring routes).
eg. { num: '18.5', arr: [ 'true', { obj: { boolFalse: 'false', nums: ['16.5', 82, '19.001'] } } ], obj: { str: 'str', boolTrue: 'true', boolTrueReal: true, nums: { numsA: [22, '15'], numsB: [18, { num: '-96.15' }] } } } becomes: { num: 18.5, arr: [ true, { obj: { boolFalse: false, nums: [16.5, 82, 19.001] } } ], obj: { str: 'str', boolTrue: true, boolTrueReal: true, nums: { numsA: [22, 15], numsB: [18, { num: -96.15 }] } } }
Parameters:
-
str
String