Clone Method

Path: /src/mod/clone.coffee compiled to /lib/mod/clone.js

This method will create a clone of the given object. As possible all methods will be cloned, but if object instances are used they will be referenced.

Example:

CoffeeScript Code
util = require 'alinex-util' test = { eins: 1 } result = util.clone test

This results to:

CoffeeScript Code
result = { eins: 1 } result is test = false

clone()

Usage:clone(obj, depth)

Parameter
  • obj - Object the object to be cloned
  • depth - Integer optional maximum level of cloning deper levels will be referenced
Return
Object the cloned object

Debugging

Debugging is possible using environment setting:

DEBUG=util:clone    -> shows each level of cloning
util:clone -> { maxCpu: '95%', maxLoad: '400%' } +0ms
util:clone    ++ [] +0ms
util:clone    -> '95%' +0ms
util:clone    <- is primitive +0ms
util:clone    -> '400%' +0ms
util:clone    <- is primitive +0ms
util:clone <- cloned object +0ms
util:clone -> { nice: -20 } +0ms
util:clone    ++ [] +0ms
util:clone    -> -20 +0ms
util:clone    <- is primitive +0ms
util:clone <- cloned object +0ms