esdmr esdmr - 1 year ago 89
Javascript Question

How to hide what we did in javascript functions?

How to hide what we did in javascript functions?

I mean Instead Of

function alpha(){
var a=Math.PI;
//other stuff
return a;

alpha();//= a
alpha;//=function alpha(){...}


alpha;//='presetted function placeholder'

Chrome Functions Also Following This. Example:

  • $ == function $(selector, [startNode]){ [Command Line API] }

  • return "function " + name + "(" + funcArgsSyntax + ") { [Command Line API] }";

Answer Source

All Chrome is doing here is setting a custom toString method in these functions. Using your example:

function alpha(){
a.toString = function() {
    return 'presetted function placeholder';

Then if you were to enter alpha in the console, in Chrome you would see:

function presetted function placeholder

Note: This doesn't really "hide" the code in any secure fashion, you could just use to get the default toString behavior.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download