JSFiddle - React, Tailwind, and code Playground
by bartek
HTML
<button onclick="create()">Create</button>
<button onclick="add()">Continue</button>
JavaScript
var sections = [],
section = {};
create = function() {
//sections.push(section); // add the current section
section = new Section(); // make a new one
section.add();
$("body").append("<br>Add to array at moment last state of object and make new one<br>" + JSON.stringify(sections) + "<br >");
}
add = function() {
section.add();
$("body").append("<br>continue only this object<br>" + JSON.stringify(sections) + "<br >");
}
function Section() {
this.array = [];
this.c = 0;
// maybe do this automatically on constructing:
//this.add();
sections.push(this);
}
Section.prototype.add = function() {
this.c++;
this.array.push(section.c);
}