yusufiqbalpk
yusufiqbalpk

Reputation: 272

How to rename javascript predefined functions

Is it possible to rename a predefined function in JavaScript as we do with php :

<?php
rename_function('mysql_connect', 'connect' );
?>

Upvotes: 1

Views: 2815

Answers (1)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

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')

Upvotes: 2

Related Questions