我有一個關於foor循環的問題。 爲什麼我的輸出每次都是「C」?for循環,元素綁定
function Dummy(){}
Dummy.prototype.a = function(){ console.log("Hello from A"); };
Dummy.prototype.b = function(){ console.log("Hello from B"); };
Dummy.prototype.c = function(){ console.log("Hello from C"); };
function hooks(obj){
\t for(method in obj){
original = obj[method];
\t obj[method] = function(){
\t console.log("Overrid %s", method);
original();
};
}
}
var instance = new Dummy();
hooks(instance);
instance.a();
instance.b();
instance.c();
我會創造一個hookable中間件
找到了解決辦法,https://stackoverflow.com/a/7269313/5781499 但是,任何人都可以解釋,爲什麼?感謝 – Marc
見https://stackoverflow.com/questions/750486/ –