2.0.0 • Published 8 years ago
swappable-proxy v2.0.0
swappable-proxy
Example:
A.js:
const SwappableProxy = require("swappable-proxy"),
B = require("./b");
function A() {
let proxy = new SwappableProxy(this);
function doSwap() {
proxy.swap(new B());
}
this.doSwap = doSwap;
function sayHi() {
console.log("My name is A");
}
this.sayHi = sayHi;
return proxy.instance;
}
module.exports = A;
B.js:
function B() {
function sayHi() {
console.log("This is B");
}
this.sayHi = sayHi;
}
module.exports = B;
index.js:
let obj = new A();
obj.sayHi(); // My name is A
obj.doSwap();
obj.sayHi(); // This is B