Создать конструктор массива объектов
В общем, я как всегда спрошу ерунду. Как создать конструктор массива обьектов?
Конечная структура должна быть примерно такая: var questions = [ { question : ['блок 1 Текст1'], answers : [ ['Вариант11 д++ текст 1 rel+2 friend+=15', function() {relation+=2}, function(){friend+=15},function(){d++ ; t=0}], ['вариант 12 д++ текст 2 rel+10 friend-=5',function() {relation+=10}, function(){friend-=5},function(){d++; t=1}], ['вариант 13 д=3 текст 2 rel-30 friend-=30}' , function() {relation-=30},function(){friend-=30}, function(){d=3; t=1 }], //d3 = end ['вариант 14 д++ текст 1 rel+25 friend-=0}', function(){relation+=25},function(){friend-=0}, function(){d++; t=0}] ] }, { question :['Блок 2 текст 1', 'блок 2 текст 2', 'блок2 тукст3'], answers : [ ['вариант 21 д++ текст3 rel/2 friend+=35', function() {relation = relation/2}, function(){friend+=35},function(){d++; t=2}], ['вариант 22 д++ текст2 rel+60 friend-=33 hideon',function() {relation+=60}, function(){friend-=33},function(){d++; t=1}, "hideon"], ['вариант 23 д=3 текст1 rel -15', function() {relation-=15},function(){friend-=30}, function(){d=3; t=0}], //d3 = end ['вариант 24 д=2 текст1 rel+30 friend-=3', function(){relation+=30},function(){friend-=3}, function(){d=2; t=0}], ['вариант 25 д++ текст1 rel+30 friend+=3 if(h==1){questions[1].answers[4][4] = undefined}', function(){relation+=30},function(){friend+=3}, function(){d=2; t=0}, function(){if(h==1){questions[1].answers[4][4] = undefined}}] ] } ] Ну и чтоб все удобно вбивалось вот, так примерно: questions[0].question[0][0] = "dssdssd"; questions[0].answers[0][0] = "dssdsdsd"; alert(questions[0].question[0] + "<br> " + questions[0].answers[0]) |
Пришел в голову такой вариант, но может есть получше способ?
var questions = []; var temp = { question: [], answers: [] } temp.question[0] = "dssdssd"; temp.answers[0] = "dssdsdsd"; questions[0] = temp alert(questions[0].question[0] + "</br> " + questions[0].answers[0]); |
Часовой пояс GMT +3, время: 05:25. |