BVB Source Codes

prettier Show object_prototype.js Source code

Return Download prettier: download object_prototype.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. function takesABool(x: boolean) {}
  4. function takesAString(x: string) {}
  5. function takesANumber(x: number) {}
  6. function takesAnObject(x: Object) {}
  7.  
  8. class Foo {}
  9.  
  10. var a = { foo: 'bar' };
  11. var b = { foo: 'bar', ...{}};
  12. var c = { foo: 'bar', toString: function(): number { return 123; }};
  13. var d : { [key: string]: string } = { foo: 'bar' };
  14. var x = new Date();
  15. var y = new Foo();
  16.  
  17. //
  18. // toString
  19. //
  20.  
  21. // call
  22. takesAString(a.toString());
  23. d.toString(); // ok, even though dict specifies strings, this is a function
  24.  
  25. // get
  26. var aToString : () => string = a.toString;
  27. var aToString2 = a.toString;
  28. takesAString(aToString2());
  29.  
  30. // set
  31. b.toString = function(): string { return 'foo'; };
  32. c.toString = function(): number { return 123; };
  33.  
  34. // override
  35. var cToString : () => number = c.toString;
  36.  
  37. // ... on a built-in instance
  38. var xToString : number = x.toString; // error
  39. var xToString2 : () => number = x.toString; // error
  40. takesAString(x.toString());
  41.  
  42. // ... on an instance
  43. var yToString : number = y.toString; // error
  44. takesAString(y.toString());
  45.  
  46. // ... on a primitive
  47. (123).toString();
  48. (123).toString;
  49. (123).toString = function() {}; // error
  50. (123).toString(2);
  51. (123).toString('foo'); // error
  52. (123).toString(null); // error
  53.  
  54.  
  55. //
  56. // hasOwnProperty
  57. //
  58.  
  59. // call
  60. takesABool(a.hasOwnProperty('foo'));
  61.  
  62. // get
  63. var aHasOwnProperty : (prop: string) => boolean = a.hasOwnProperty;
  64. var aHasOwnProperty2 = a.hasOwnProperty;
  65. takesABool(aHasOwnProperty2('bar'));
  66.  
  67. // set
  68. b.hasOwnProperty = function() { return false; };
  69.  
  70. // ... on a built-in instance
  71. var xHasOwnProperty : number = x.hasOwnProperty; // error
  72. var xHasOwnProperty2 : (prop: string) => number = x.hasOwnProperty; // error
  73. takesABool(x.hasOwnProperty('foo'));
  74.  
  75. // ... on an instance
  76. var yHasOwnProperty : number = y.hasOwnProperty; // error
  77. takesABool(y.hasOwnProperty('foo'));
  78.  
  79.  
  80. //
  81. // propertyIsEnumerable
  82. //
  83.  
  84. // call
  85. takesABool(a.propertyIsEnumerable('foo'));
  86.  
  87. // get
  88. var aPropertyIsEnumerable : (prop: string) => boolean = a.propertyIsEnumerable;
  89. var aPropertyIsEnumerable2 = a.propertyIsEnumerable;
  90. takesABool(aPropertyIsEnumerable2('bar'));
  91.  
  92. // set
  93. b.propertyIsEnumerable = function() { return false; };
  94.  
  95. // ... on a built-in instance
  96. var xPropertyIsEnumerable : number = x.propertyIsEnumerable; // error
  97. var xPropertyIsEnumerable2 : (prop: string) => number =
  98.   x.propertyIsEnumerable; // error
  99. takesABool(x.propertyIsEnumerable('foo'));
  100.  
  101. // ... on an instance
  102. var yPropertyIsEnumerable : number = y.propertyIsEnumerable; // error
  103. takesABool(y.propertyIsEnumerable('foo'));
  104.  
  105.  
  106. //
  107. // valueOf
  108. //
  109.  
  110. // call
  111. takesAnObject(a.valueOf());
  112.  
  113. // get
  114. var aValueOf : () => Object = a.valueOf;
  115. var aValueOf2 = a.valueOf;
  116. takesAnObject(aValueOf2());
  117.  
  118. // set
  119. b.valueOf = function() { return {}; };
  120.  
  121. // ... on a built-in instance
  122. var xValueOf : number = x.valueOf; // error
  123. takesANumber(x.valueOf());
  124.  
  125. // ... on an instance
  126. var yValueOf : number = y.valueOf; // error
  127. takesAnObject(y.valueOf());
  128.  
  129. // ... on a literal
  130. var strValueOf : string = ("foo").valueOf();
  131. var numValueOf : number = (123).valueOf();
  132. var boolValueOf : boolean = (true).valueOf();
  133.  
  134. //
  135. // toLocaleString
  136. //
  137.  
  138. // call
  139. takesAString(a.toLocaleString());
  140.  
  141. // get
  142. var aToLocaleString : () => string = a.toLocaleString;
  143. var aToLocaleString2 = a.toLocaleString;
  144. takesAString(aToLocaleString2());
  145.  
  146. // set
  147. b.toLocaleString = function() { return 'derp'; };
  148.  
  149. // ... on a built-in instance
  150. var xToLocaleString : number = x.toLocaleString; // error
  151. var xToLocaleString2 : () => number = x.toLocaleString; // error
  152. takesAString(x.toLocaleString());
  153.  
  154. // ... on an instance
  155. var yToLocaleString : number = y.toLocaleString; // error
  156. takesAString(y.toLocaleString());
  157.  
  158.  
  159. //
  160. // constructor
  161. //
  162.  
  163. var k : Object = a.constructor;
  164. (123).constructor;
  165.  
downloadobject_prototype.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