javascript - Return all properties in JS object to "empty" state -
I wonder if the jQuery function has any utility function, then the JS object is scaled down ( There are more than one possible result, not sure what is most useful yet):
{// original object foo: "bar", arr: [1, 2, 3], Sub: {a: 4, b: 5, subsub: {c: 6}}} {// cut, version 1 foo: "", arr: [], sub: {}} {// has been reduced, Version 2 foo: "", arr: [], sub: {subsub: {}}} {// tuncated, variant 3 fu: "", ar: [], sub: {a: 0, b: 0, subsub : {C: 0}}} If not, then all the properties are more cunning than iterated iterations, check the type and reset / reset as needed?
Call Constructor for each property to create an object's empty object. [obj] = obja [k] & amp; Amp; Obj [k] .constructor (); }
This will also return the numbers to 0, false to the boleys, so far dates, and regexps to empty (but Naoyen Naain will remain).
To continuously do this, maintain the object-valuable properties, but also emptying them (version 3):
function throoncate (obj) {for ( Var k in obj) {var ctor = obj [k] & amp; Amp; ; Obj [k] .constructor; If cut (ctor === object) (ojj [k]); Else if (ctor) obj [k] = ctor (); }} To eliminate the number (version 2), add a check:
function in the threnetate (obj) {for (var k ) {Var Ctor = obj [k] & amp; Amp; Obj [k] .constructor; If cut (ctor === object) (ojj [k]); Else if (ctor === number) obj [k] remove; Else if (ctor) obj [k] = ctor (); }}
Comments
Post a Comment