Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyObjectvtable = [];
- function MyInnerObject() {}
- function MyObject() {
- this.mNum = 0;
- this.mObject = new MyInnerObject();
- this.mStr = "hello!";
- this.vtable = MyObjectvtable;
- }
- function VirtualMethod() {
- var that = this;
- console.log(String(that.mNum) + that.mStr);
- };
- function NonVirtual(that) {
- console.log(String(that.mNum) + that.mStr);
- }
- MyObject.prototype.VirtualMethod = VirtualMethod;
- MyObjectvtable[0] = VirtualMethod;
- MyObjectvtable[1] = NonVirtual;
- pobj = new MyObject();
- pobj.VirtualMethod();
- NonVirtual(pobj);
- pobj.vtable[0].bind(pobj)();
- pobj.vtable[1](pobj);
Add Comment
Please, Sign In to add comment