cast.js 978 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <rtl code>
  2. var m = function (){
  3. function Base(){
  4. }
  5. function Derived1(){
  6. Base.call(this);
  7. this.field1 = 0;
  8. }
  9. RTL$.extend(Derived1, Base);
  10. function Derived2(){
  11. Derived1.call(this);
  12. this.field2 = 0;
  13. }
  14. RTL$.extend(Derived2, Derived1);
  15. function PAnonymousDerived(){
  16. Base.call(this);
  17. this.field3 = 0;
  18. }
  19. RTL$.extend(PAnonymousDerived, Base);
  20. var pb = null;
  21. var pd1 = null;
  22. var pd2 = null;
  23. var pad = null;
  24. function p(b/*VAR Base*/, d1/*VAR Derived1*/){
  25. RTL$.typeGuard(b, Derived1).field1 = 0;
  26. RTL$.typeGuard(b, Derived2).field2 = 1;
  27. RTL$.typeGuard(d1, Derived2).field2 = 2;
  28. }
  29. pd2 = new Derived2();
  30. pb = pd2;
  31. pd1 = pd2;
  32. RTL$.typeGuard(pb, Derived1).field1 = 0;
  33. RTL$.typeGuard(pb, Derived2).field2 = 1;
  34. RTL$.typeGuard(pd1, Derived2).field2 = 2;
  35. RTL$.typeGuard(pb, Derived1).field1 = 0;
  36. RTL$.typeGuard(pb, Derived2).field2 = 1;
  37. RTL$.typeGuard(pd1, Derived2).field2 = 2;
  38. pad = new PAnonymousDerived();
  39. pb = pad;
  40. RTL$.typeGuard(pb, PAnonymousDerived).field3 = 3;
  41. p(pd2, pd2);
  42. }();