0

I want to have two separate files in JavaScript with the same name , can i do it in javascript ? I want to expose only part of the code to the user and not all the file (Do we have any concept on javascript like the c# partial classes ?)

Thanks Shimon

2 Answers2

2

In the Web Browser, all of the JavaScript code is interpreted locally on the user's machine. So for the Web Browser to be able to interpreted correctly it needs all of the source code. So the answer to your main question is "no".

The closest solution to your problem is doing some sort of obfuscation of the source code. When you do that, it makes the source code very hard for the user to read the source code, but the Web Browser can still interpret it.

To answer the last question, all objects in JavaScript can be extended like partial classes in C#.

Sam
  • 2,166
  • 2
  • 20
  • 28
0

Nope - you can't fully hide JavaScript from your end users. The users browser needs to be able to parse the code and as such the user will have access to it as well.

What you can try to is use some form of code obfusication. This will still allow the user's browser to parse the code but will make it very difficult for a user to read and understand what's going on.

That said, it's not impossible for a user to un-obfusicate the code and see the logic behind it - it is just another layer of security but by no means fool proof.

Community
  • 1
  • 1
Lix
  • 47,311
  • 12
  • 103
  • 131