API Docs for: 0.3.0
Show:

Utils.copyParam Class

Module: Utils

copy all allowed variables from params to target, using defaultContext for set default values.

Note: inherit is not a class but a standalone function.

copyParam is used principally for easily copy parameters from hash objects. All variables must be present in defaultContext, so adding an unespected variable will not override target object. All values in defayultContext are also copied as default values.

If you want to allow some properties, but not to set default value, you can create the property and set it to undefined.

Constructor

Utils.copyParam

(
  • target
  • params
  • defaultContext
)

Parameters:

  • target Object
  • params Object
  • defaultContext Object

Example:

:

 var target = {};
 var defaultContext = {
     foo:    "default value",
     bar:    33,
     baz:    undefined           // baz is allowed, but has not default value.
 };

 Utils.copyParam(target, { foo: "some value", unknown: 3 }, defaultContext);
 console.log(target);
 // Object {foo: "some value", bar: 33}
 //unknown is not copied because not allowed.

Item Index