BVB Source Codes

prettier Show instanceof.js Source code

Return Download prettier: download instanceof.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. // x instancof t
  4. class X1 { foo: number; };
  5. class X2 { foo: string; };
  6.  
  7. function x(b) { return b ? new X1 : new X2; }
  8.  
  9. function consumer1(b) {
  10.     var g = x(b);
  11.     if (g instanceof X2) g.foo = '1337';
  12.     else g.foo = 1337;
  13. }
  14.  
  15. function consumer2(b) {
  16.     var g = x(b);
  17.     if (g instanceof X1) g.foo = '1337';  // oops
  18. }
  19.  
  20. // x.y instanceof t
  21. class Y1 { bar: X1; };
  22. class Y2 { bar: X2; };
  23.  
  24. function y(b) { return b ? new Y1 : new Y2; }
  25.  
  26. function consumer3(b) {
  27.     var g = y(b);
  28.     if (g.bar instanceof X2) g.bar.foo = '1337';
  29.     else g.bar.foo = 1337;
  30. }
  31.  
  32. function consumer4(b) {
  33.     var g = y(b);
  34.     if (g.bar instanceof X1) g.bar.foo = '1337';  // oops
  35. }
  36.  
  37. // x.y.z instance of t
  38. class Z1 { baz: Y1; };
  39. class Z2 { baz: Y2; };
  40.  
  41. function z(b) { return b ? new Z1 : new Z2; }
  42.  
  43. function consumer5(b) {
  44.     var g = z(b);
  45.     if (g.baz.bar instanceof X2) g.baz.bar.foo = '1337';
  46.     else g.baz.bar.foo = 1337;
  47. }
  48.  
  49. function consumer6(b) {
  50.     var g = z(b);
  51.     if (g.baz.bar instanceof X1) g.baz.bar.foo = '1337';  // oops
  52. }
  53.  
  54. // this instanceof t
  55. class C {
  56.   m() {
  57.     if (this instanceof D)
  58.       alert(this.s);
  59.     else
  60.       alert("nope");
  61.   }
  62. }
  63.  
  64. class D extends C {
  65.   s: string;
  66.   constructor() {
  67.     super();
  68.     this.s = "yup";
  69.   }
  70. }
  71.  
  72.  
  73. function foo0(x: Array<number> | number) {
  74.   if (x instanceof Array) {
  75.     x[0] = 123;
  76.   } else {
  77.     x++;
  78.   }
  79. }
  80.  
  81. function foo1(x: Array<number> | number) {
  82.   if (x instanceof Array) {
  83.     x++; // error
  84.   } else {
  85.     x[0] = 123; // error
  86.   }
  87. }
  88.  
downloadinstanceof.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top