當創建一個JavaScript代理這樣JavaScript代理,從你的目標的內部HOWTO觸發陷阱
var t = function() {
self = this;
this.a = "abc";
someFunc: function() {
self.a = "def";
}
}
target = new t();
var p = New Proxy(target, {
set: function(){
//this will never be called when the someFunc changes the a field.
}
})
p.someFunc();
設定的「陷阱」將永遠不會被調用我沒有問題,理解爲什麼出現這種情況,但應該如何一個解決這樣的情況?
一個解決辦法是,以暴露自我variale到外面,讓「某人」將其更改爲代理,不是很obviouse使用的T對象的人....
是否有任何其他方式? 我濫用代理嗎?
「*一種解決方案是將自變量暴露在外面*」 - [你已經這麼做](http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html )?添加一個'var'!並修復所有其他語法錯誤,如'someFunc:'或'New'。 – Bergi