Disable view code of function javascript

Total Post:70


 1526  View(s)
Rate this:
Hi Everyone!

Like this, if I made a function:

    function a() {
I don't want you to be able to view the code like:

Returns all the code but

Returns the alert

When doing eval(a) I want it to not return the code, just nothing how?

Thanks in advance!
  1. Re: Disable view code of function javascript

    Hi Lois!

    Always encapsulate your code in an IIFE (Immediately Invoked Function Expression) so you don't leak variables to the global scope:

      function a() {
      // more stuff...

    console.log(eval(a)); //=> Uncaught ReferenceError: a is not defined 
    You can also use a little trick to hide the function code with bind:

    var a = function a() {

    console.log(eval(a)); //=> function () { [native code] }

    Whenever you think about using eval, think twice, there's probably a better way to do it. If you just want to run the function, just do a(). No need for eval there.

    I hope it resolve your problem!


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.