参考功能

bel*_*ykh 1 javascript function

我试图在JavaScript中引用函数来混淆源代码

var g = document.getElementById;
Run Code Online (Sandbox Code Playgroud)

但是该通话g('id')会导致Google Chrome出错TypeError: Illegal invocation

Den*_*ret 5

函数调用的上下文必须是文档.使用

var g = document.getElementById.bind(document);
Run Code Online (Sandbox Code Playgroud)

如果您想与IE8(没有绑定)兼容,请使用

var g = function(id){
    return document.getElementById(id);
}
Run Code Online (Sandbox Code Playgroud)