0

I am abot to refactor code, can somebody tell me what the purpose of void with arguments is:

 case "JAVASCRIPT":
  let name= keyObject.customer.name;
  let ref = keyObject.customer.ref;
  let id1 = keyObject.customer.id1;
  let id2 = keyObject.customer.id2;
  let secNr= keyObject.customer.secNr;
  let key = "";
  void(navn + ref + id1 + id2 + secNr + "kijn" + key); // <--- WTF IS THIS...

  if (selectedItem.key[0] !== "kunj") {
    key = keyObject.keys[0] + "" + keyObject.keys[1];
  }
  let pathArray = window.location.pathname.split("/");
  let returnUrl = pathArray.slice(3).toString().replace(new RegExp(",", "g"), "/");
  void(returnUrl); <-- and this
  eval(selectedItem.url);
  break;

Is it secure to refactor like this:

case "JAVASCRIPT":
  eval(selectedItem.url);
  break;
  • Yeah, that don't make a whole lotta sense. – deceze Jun 18 '18 at 12:39
  • This code is the worst code ive seen for a while. `void` does nothing, its like `function void(i, dont, care) { return undefined; }` and it makes no sense to use it here. – Jonas Wilms Jun 18 '18 at 12:40
  • void basically takes in the expression and then returns undefined, soooooo returning `undefined` – t.. Jun 18 '18 at 12:40
  • 1
    `void expr` is used to evaluate en expression and then return undefined. http://2ality.com/2011/05/void-operator.html – Olian04 Jun 18 '18 at 12:40
  • 3
    it forces the expression to execute. maybe some getters are involved and some side effects are wanted ... which would be smelling. – Nina Scholz Jun 18 '18 at 12:41
  • @Nina I don't even see how a getter could be involved there. `.toString`?! If so… – deceze Jun 18 '18 at 12:43
  • @deceze `with({ get navn() { alert("hey"); }}) { /*...*/ }` – Jonas Wilms Jun 18 '18 at 12:48
  • 1
    @JonasW. That would be pure evil. Given that there's another `void(returnUrl)` below, which is clearly just a string, I'd first blame incompetence though. Not to mention the `eval` there. – deceze Jun 18 '18 at 13:00

0 Answers0