Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

triggerfinger12

Well-Known Member
Apr 17, 2017
255
457
89
Rock
55 So, just in passing, I want to give a shout-out to my fellow memers at r/PrequelMemes, although I am part-time. :)
It is the place where one goes if he needs to obtain the high ground. You must say "Hello there" to every General Kenobi you see. If you want Unlimited Power, it is the place for you.
A few quick rules:
  1. Do it.
  2. You must include not just the men, but the women, and the children too.
  3. To be Frank, Sheev Palpatine is the Senate
  4. Can you make any line from the Star Wars Prequels a meme? Yep.
  5. Possibly.
  6. Did you ever hear the tragedy of Darth Plagueis the Wise?
  7. What about the Droid attack on the Wookies?

  8. 4dTNuk84m7zxpNI7pnb8UE2fsUtI9_2gK44kli4gZxc.jpg
 
Last edited:
  • Like
Reactions: MrMonsterGuy18

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
58 meanwhile, there are games like Sonic 3D that can't crash no matter what you throw at it
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
54
Code:
let inputData = JSON.parse(JSON.stringify(this.inputFieldData));
Its a sad day when the above line is the only "good" option :(
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
56
55 How do you mean?
  1. What does it do?
  2. Why is it bad?
  3. Why is it the only good option?
  4. What are you trying to do?
JSON.stringify() takes an object and turns it into a text representation of said object.
JSON.parse() is the opposite of it (it takes a text representation of an object and turns it into a real object.)

Its bad because it looks like an hack (and lets be honest, it is a hack)
The reason I need it is because I need to clone an object (and all the objects inside of it). I can't just write
Code:
let inputData = this.inputFieldData;
because in JS objects are always passed by reference (thus, if I do that inputData refers to the same memory as this.inputFieldData and as a result any changes I do to inputData will also happen to this.inputFieldData)

The reason I need it is because I need to make some changes to the object without actually editing the real object.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
58 No copy constructor on it?
59 the thing is, I need this whole object but I need to edit all the names. And all other ways I know off aren't a deep copy.
upload_2017-10-14_22-46-19.png

I already tried Object.merge but that ended up looking worse than the current code (not to mention that the current code is probably faster
For reference the current code is now:
Code:
//make a deep clone
   let inputData = JSON.parse(JSON.stringify(this.inputFieldData));
   if(inputData.baseName){
     inputData.inputs.forEach(
       (value,key)=>{
         inputData.inputs[key].input.name =
           this.inputFieldData.baseName+
           "["+this.inputCount+"]"+
           value.input.name;
         inputData.inputs[key].input.cssClass =
           this.inputClass +
           " "+
           (inputData.inputs[key].input.cssClass || "") ;
       }
     )
     delete inputData.baseName,
   }
Where as with the Object.mergeI had to loop over each input and make new objects where the name was changed and then merge them inside yet another object.
I then had to create yet another merge. This time to put the input and label together and then put all those objects together using object.merge.

So... one loop is probably the cleanest.