JSON.stringify(Object),不考虑Object.addObject = new Object()

时间:2019-04-22 09:10:23

标签: javascript json object stringify

var oSamples = new Samples();

//Samples Object
function Samples() {
    this.sampleID = new Array();
    this.oSampleGroup = new SampleGroup();
    this.iSampleCount = 0;
    this.sampleName = new Array();
}

//SampleGroup Object
function SampleGroup() {
    this.oSample = new Array();
    this.iSampleCount = 0;
    this.addSample = function(barcode, date, time, collectedAt) {
        this.oSample[this.iSampleCount] = new Sample(barcode, date, time, collectedAt);
        this.iSampleCount += 1;
    }
}

// add a sample
function Sample(barcode, date, time, collectedAt){
   this.sCarcode = barcode;
   this.dDate = date;
   this.sTime = time;
   this.sCollectedDateTime = collectedAt;
}

JSON.stringify(oSamples);

上面的示例对象的严格内容在sampleGroup对象中不包含addSample方法。

0 个答案:

没有答案