- Source:
Methods
(static) getval(subscript, root) → {string}
Get a value deeply from an object without crashing on nulls.
This function is dynamic, so can be bound or just assigned to an
object.
Can be used to "index" arrays.
Parameters:
Name | Type | Description |
---|---|---|
subscript |
string | the subscript string, i.e. 'a.b.c.prop' |
root |
Optional.<object> | the root object. Defaults to this. |
- Source:
Returns:
the value of the prop, if exists else undefined
- Type
- string
Example
var obj = {a:{b:{c:{}}}}
var c = sputils.lib.getval('a.b.c', obj);
c === obj.a.b.c;
var none = sputils.lib.getval('a.b.1.notHere', obj);
none === void 0;
// dynamic binding
testObjects.getval = sputils.lib.getval;
expect(testObjects.getval('a.b')).to.equal(testObjects.a.b);
// any kind of property name is allowed, excepting period.
var getval = sputils.lib.getval;
var res = getval('a.b.d.2.long prop name', testObjects);
expect(res).to.equal(testObjects.a.b.d[2]['long prop name']);
(static) tap()
"taps" a function to produce a side effect
but wrap it in an identity fn, which simply
returns the argument which was passed to it.
- Source: