code: function (obj) {
          return _.cloneDeepWith(obj, function (value) {
              // falls back to default deepclone if object does not have explicit toJSON().
              if (value && _.isFunction(value.toJSON)) {
                  return value.toJSON();
              }
          });
      }
docs: Creates a clone of an object, but uses the toJSON method if available.
  
  @param {Object} obj
  @returns {*}