Stringifying

API ReferenceUtilsStringifying

Source


utils.simplify()

Static method of
utils
Parameters
  • object — Object
  • options — Objectoptional

Convert the given object into the most simplified format with no cyclic references and more.

Such object can be easily stringified later using standard JSON.stringify().

Use utils.assemble() function to restore the object into the initial structure.

Second parameter is an config object (all 'false' by default):

  • properties - save properties descriptors (getters, config etc.),
  • protos - save protos as objects,
  • constructors - include constructor functions.
var obj = {};
obj.self = obj;
console.log(JSON.stringify(utils.simplify(obj)));

If protos is false and constructors is true, object will be recognized as an instance.

function Sample(){
  this.fromInstance = 1;
}
Sample.prototype.fromPrototype = 1;

var sample = new Sample;
var parts = utils.simplify(sample, {constructors: true});
var clone = utils.assemble(json);

console.log(clone instanceof Sample)
// it's true because 'protos' option is false and 'constructors' is true
// won't work for json, because functions are not stringified ...

Source


utils.assemble()

Static method of
utils
Parameters
  • object — PlainObject

Backward utils.simplify() operation.

Source

results matching ""

    No results matching ""