Object Adapter Module for Base Library
Eric Bréchemier © 2011-2013, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved
BSD License http://creativecommons.org/licenses/BSD/
2013-09-10
lb. | Object Adapter Module for Base Library |
Functions | |
has(object,property[,...]): boolean | Check whether an object property is present and not null nor undefined. |
clone(object[,deep]): object | Get a shallow or a deep copy of an object. |
Check whether an object property is present and not null nor undefined.
A chain of nested properties may be checked by providing more than two arguments.
The intent of this method is to replace unsafe tests relying on type coercion for optional arguments or object properties:
function on(event,options){ options = options || {}; // type coercion if (!event || !event.data || !event.data.value){ // unsafe due to type coercion: all falsy values '', false, 0 // are discarded, not just null and undefined return; } // ... }
with a safer test without type coercion:
function on(event,options){ options = or(options, {}); // no type coercion if ( !has(event,'data','value') ){ // safe check: only null/undefined values are rejected; return; } // ... }
object | any, an object or any other value |
property | string, the name of the property to look up |
... | string, additional property names to check in turn |
Get a shallow or a deep copy of an object.
object | object, an object or array |
deep | boolean, optional, defaults to false, whether to make a deep copy (true) or a shallow copy (false) |
In the case of a deep copy, there must be no cyclic references in the given object.