每次调用时我都想执行一些代码appendChild
。让我们假设我无法知道它会在何时何地被调用。我想我可以使用原型来做到这一点,但他们似乎没有工作:
var actAppendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function(node){
actAppendChild.call(this,node);
//execute custom code here...
console.log("foo");
}
document.body.appendChild(someNode);
但是“foo”不会打印到控制台,也不会打印到新原型函数中的任何代码,就此而言。我究竟做错了什么?