0

Alright so I've a function (not exactly the one written bellow, that one is just an example)

function test() 
{
  alert("Hello");
}

Now the problem is that people are able to go into console and just type "test()" and call the function.

Is there a way to prevent this? I dont want of people to call functions from the console.

Tomislav Tomi Nikolic
  • 608
  • 3
  • 10
  • 15

1 Answers1

0

You can narrow the context that your function is executed in, eg:

(function() {
  function test() { /* Do anything */ }
  test();
  // Call test anywhere here
})()

test(); // Error: test is undefined
corvus
  • 513
  • 1
  • 3
  • 13