How to rename javascript predefined functions

霸气de小男生 提交于 2020-01-15 11:06:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!