Guest User

Untitled

a guest
May 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. MyObjectvtable = [];
  2. function MyInnerObject() {}
  3.  
  4. function MyObject() {
  5. this.mNum = 0;
  6. this.mObject = new MyInnerObject();
  7. this.mStr = "hello!";
  8. this.vtable = MyObjectvtable;
  9. }
  10.  
  11. function VirtualMethod() {
  12. var that = this;
  13. console.log(String(that.mNum) + that.mStr);
  14. };
  15.  
  16. function NonVirtual(that) {
  17. console.log(String(that.mNum) + that.mStr);
  18. }
  19.  
  20. MyObject.prototype.VirtualMethod = VirtualMethod;
  21. MyObjectvtable[0] = VirtualMethod;
  22. MyObjectvtable[1] = NonVirtual;
  23.  
  24. pobj = new MyObject();
  25.  
  26. pobj.VirtualMethod();
  27.  
  28. NonVirtual(pobj);
  29.  
  30. pobj.vtable[0].bind(pobj)();
  31.  
  32. pobj.vtable[1](pobj);
Add Comment
Please, Sign In to add comment