问题
Is it possible to rename a predefined function in JavaScript as we do with php :
<?php
rename_function('mysql_connect', 'connect' );
?>
回答1:
It's possible in js too. See this function.
function rename_function(obj, oldf, newf){
obj[newf]=obj[oldf];
delete obj[oldf];
}
Here obj
is the closure of the function. Normally if your functions have no closure it's under window object. rename_function(window, 'alert', 'al')
来源:https://stackoverflow.com/questions/10245407/how-to-rename-javascript-predefined-functions