0
我試圖覆蓋一個名爲「localStorage」的本地方法,用於INSIDE對象中的函數。覆蓋原生方法和對象INSIDE特定對象
這裏是我想要做一個要點:
function SomeObject(){
this.localStorage = "aaa"; //block access to localStorage for functions INSIDE this object.
... (some more code here)
_testRun(){
window.testA = localStorage; //chose to store the instance on a window (global-like) object
}
this.testRun = function(){ _testRun(); };
this.testRun2 = function(){ window.testB = localStorage;};v
}
var a = new SomeObject();
a.testRun();
a.testRun2();
(after this, when I look up window.testA and window.testB, they both point to the Native localStorage, not the custom one inside the SomeObject.)
BTW,我不想覆蓋原有的功能,整個文檔。 (即可能使用本地localStorage的對象外)
關於如何做到這一點的任何建議/解決方案?謝謝!
嘗試window.testB = this.localStorage,它應該涉及到範圍變量。 – Derek 2013-03-02 06:56:08