如何隐藏我们在javascript函数中所做的事情?
我的意思是代替
function alpha(){
var a=Math.PI;
//other stuff
return a;
}
alpha();//= a
alpha;//=function alpha(){...}
要
alpha;//='presetted function placeholder'
Chrome Functions Also Following This。例如:
$ == function $(selector, [startNode]){ [Command Line API] }
return "function " + name + "(" + funcArgsSyntax + ") { [Command Line API] }";
答案 0 :(得分:1)
所有Chrome在此处都在为这些功能设置自定义toString
方法。使用您的示例:
function alpha(){
}
a.toString = function() {
return 'presetted function placeholder';
};
然后,如果您要在控制台中输入alpha
,则可以在Chrome中看到:
function presetted function placeholder
注意:这并不是以任何安全的方式“隐藏”代码,您只需使用Function.prototype.toString.call(alpha)
来获取默认的toString
行为。