function js_hook(_obj,_fn_name,_hook_call) { var _class = _obj; if(typeof _obj === "function"){ _class = _obj.constructor; }; var original = _class[_fn_name]; _class[_fn_name] = function () { return _hook_call.call(this,original,arguments); }; };
使用方法
js_hook(document,"write",function (org,args) { console.debug(args); args[0] = "hook_"+args[0]; org.apply(this,args); });
document.write("test");