Dans ce code, j'ai créé une fonction appelée someFunction. Ensuite, j'ai modifié Function.prototype.apply et appel des méthodes. Donc, au lieu de mon code de fonction fonctionne, je cours mon code d'interception (qui montre une alerte). Mais ni "call", ni "apply" n'intercepte un appel de méthode direct. Est-il possible d'intercepter cela?Puis-je intercepter une fonction appelée directement?
Function.prototype.call = function(){alert("call");};
Function.prototype.apply = function(){alert("apply");};
function someFunction(){}
window.onload = function(){
someFunction.call(this); //call alert is shown
someFunction.apply(this); //apply alert is shown
someFunction(); //how can I intercept this?
}
Peut-être que je peux changer la fonction Function.constructor de sorte que chaque fonction renvoyée aura votre wrapper autour d'elle. – yilmazhuseyin
@yilmazhuseyin: non, vous ne pouvez pas. Changer le constructeur * Function * vous permettrait seulement de remplacer les fonctions créées avec 'new Function (str)'. –
oui vous avez raison. function newConstructor() {alert ("a");}; Function.prototype.constructor = newConstructor; ne fonctionnait pas. – yilmazhuseyin