Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以像使用 php 一样重命名 JavaScript 中的预定义函数:
<?php rename_function('mysql_connect', 'connect' ); ?>
js也是可以的。看到这个函数。
function rename_function(obj, oldf, newf){ obj[newf]=obj[oldf]; delete obj[oldf]; }
这里obj是函数的闭包。通常,如果您的函数没有闭包,则它位于 window 对象下。rename_function(window, 'alert', 'al')
obj
rename_function(window, 'alert', 'al')