Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //Here's the object I'm trying to JSON.stringify
  2.  
  3. var collection = function () {
  4. this.keys = [];
  5. this.events = [];
  6.  
  7. var timer;
  8. var starttime;
  9. var stoptime;
  10.  
  11. var key_definition = function () {
  12. return {
  13. id: -1,
  14. label: null,
  15. description: null,
  16. letter: null,
  17. position: -1,
  18. type: -1
  19. };
  20. }
  21.  
  22. this.newkey = function(id0, label0, description0, letter0, position0, type0) {
  23. this.keys.push(key_definition());
  24. var key = this.keys[this.keys.length-1];
  25. key.id = id0;
  26. key.label = label0;
  27. key.description = description0;
  28. key.letter = letter0;
  29. key.position = position0;
  30. key.type = type0;
  31. }
  32.  
  33. var event_definition = function() {
  34. //this.eventstream.push({event: this.element.buttondefinition,type: this.element.buttontype,state: this.element.buttonstate,time: ms_time});
  35.  
  36. return {
  37. time: -1,
  38. buttonid: -1,
  39. state: -1 //0 off, 1 on
  40. };
  41. }
  42.  
  43. this.newevent = function(time0, id0, state0) {
  44. console.log("newevent");
  45. this.events.push(event_definition());
  46. var event = this.events[this.events.length-1];
  47. event.time = time0;
  48. event.id = id0;
  49. event.state = state0;
  50. }
  51. };
  52.  
  53. var cc = new collection();
  54.  
  55. Here's the section where i try to stringify it:
  56.  
  57.  
  58. var str;
  59.  
  60. str = "<body>";
  61.  
  62. str += "<a href=selectkey.php?collectscreen=1><p>Reload</p></a>";
  63. str += "<a href=selectkey.php><p>Select Key File</p></a>";
  64. str += "<p>data</p><hr>\n";
  65. for (var i = 0; i < cc.events.length; i++) {
  66. str += cc.events[i].time + " " + cc.keys[cc.events[i].id].label + " " + cc.events[i].id + " " + cc.events[i].state + "<br>\n";
  67. }
  68. str += "<p><hr>";
  69. str += JSON.stringify(cc);
  70. str += "</body>";
  71.  
  72. document.write(str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement