如何在单击“创建”按钮时将对象的最后状态添加到数组并创建新的清理准备继续,如果单击“继续”按钮仅修改实际对象,现在修改部分数组中的所有对象?
说明材料:
HTML:
<button onclick="create()">Create</button>
<button onclick="add()">Continue</button>
JavaScript:
var sections = [];
create = function() {
sections.push(section);
section.array = [];
section.c = 0;
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 >");
}
var section = {
array: [],
c: 0,
add: function() {
section.c++;
section.array.push(section.c);
}
}