Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes a Javascript anonymous function remain visible? (Using a Java applet, a way to hide JS code)
    text
    copied!<p>I'm writing an application using Javascript. I'm searching for a way to hide my code and I suppose I've found one, using Java Applet. </p> <p>Anyway, I think that should be possible only if js <em>anonimous functions</em>' code doesn't remain accessible in any way after it's been evaluated.</p> <pre><code>(function(){...}).call(obj) </code></pre> <p>Applets can get a reference to the browser's window they are in, and call its <code>eval</code> method to evaluate js code:</p> <pre><code>// java code JSObject window = JSObject.getWindow(this); window.eval( "(function(){" + ... + "}).call(" + thisObjectName + ")" ); </code></pre> <p>Thus, I can change my js code, in the way that some functions, instead of having their code inside, call an applet function that asks the window to <code>eval</code> the original js function code, passing to the window an anonimous function, so that no function reference remains. Of course, js function must give to java function the name of the object (the <code>this</code>), and java function must compose the anonimous function adding a call to the <code>call(objectName)</code> method, to use the <code>this</code> reference properly.</p> <pre><code>MyJsClass.prototype.func = function() { ... }; </code></pre> <p>becames:</p> <pre><code>MyJsClass.prototype.func = function() { ... myApplet.evalJsCode(thisObjectName); ... }; </code></pre> <hr> <p><strong>[UPDATE]</strong> My idea was not good for 2 reasons</p> <ol> <li><p>Java bytecode (.class) is easy to de-compile (thanks to <a href="https://stackoverflow.com/users/182668/pointy">Pointy</a>)</p></li> <li><p>The <code>window.eval</code> function called by the Applet is the very same you can override via javascript (thanks to <a href="https://stackoverflow.com/users/697154/yoshi">Yoshi</a>)</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload