5

I have used JavaScript since it was called LiveScript,
and know to value persons who say "Eval is Evil"
(Classic SharePoint uses eval() at least 5 times in its core code)

So when a new kid on the block gets (a bit) Evil,
starts telling you how to behave,
and restricts your capabilities,
😇 you counter it with Creativity:

  this.domElement.innerHTML = eval(
      `var s=document.createElement("SCRIPT");
       s.type="text/javascript";
       s.src="https://365csi.nl/hello_spfx.CSI.js";
       document.head.appendChild(s);');

Questions

  • Can we safely use standard ECMAscript eval() in SPFX?

  • There are ways of crippling eval();
    as Classic SharePoint uses eval itself in its core code,
    will SPFx / New Experience not be more Evil on us?

  • Is eval used in new SharePoint code?
    Haven't had time yet to do a code analysis...
    Seems kinda pointless with an update every couple of weeks:

    (script:0 is my auto-check if UserCustomActions are enabled again)

6
  • Clever title, but not sure what you're asking here...
    – SPDoctor
    Commented Aug 26, 2016 at 9:14
  • Question: can I safely use standard eval() in SPFx? Commented Aug 26, 2016 at 10:18
  • Okay can you edit the question so the title is clear, and just one question that maybe someone working on SPFx can answer. Thanks.
    – SPDoctor
    Commented Aug 26, 2016 at 10:25
  • This is probably gonna end up a Community question anyway, as there won't be a definite right/wrong answer, more likely just an overwhelming "No, don't do that. You can, but there's probably better way".
    – James Love
    Commented Aug 30, 2016 at 8:42
  • Would you mind explaining what you mean by "restrict your capabilities", (why you need a workaround)?
    – Christophe
    Commented Oct 27, 2016 at 15:16

1 Answer 1

3

I.believe you can use it. As you mention its generally not a good practice, but you can use it. I don't believe we use it in any of our code. Are you encountering any issue?

1
  • 2
    Honestly I don't like this answer. You can't make such a statement on the safety of eval without knowing the details of the implementation and the reasons behind it.
    – Christophe
    Commented Oct 27, 2016 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.