I want to override a function of an object such that its current functionality remains intact. See the following example:
Let say we want to log the text whenever the developer uses document.write something like:
document.write  = function (text) {
    console.log("You have written ["+ text + "] to document");
    //Now call actual document.write
    document.write(text);
}
//Lets use the above function
document.write("America");
In above code the word America must be written to document and as well to the console. Is it possible? How it can be done?
 
     
    