bool.js.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: bool.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: bool.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * @constructor
  21. * Sk.builtin.bool
  22. *
  23. * @description
  24. * Constructor for Python bool. Also used for builtin bool() function.
  25. *
  26. * Where possible, do not create a new instance but use the constants
  27. * Sk.builtin.bool.true$ or Sk.builtin.bool.false$. These are defined in src/constant.js
  28. *
  29. * @extends {Sk.builtin.object}
  30. *
  31. * @param {(Object|number|boolean)} x Value to evaluate as true or false
  32. * @return {Sk.builtin.bool} Sk.builtin.bool.true$ if x is true, Sk.builtin.bool.false$ otherwise
  33. */
  34. Sk.builtin.bool = function (x) {
  35. Sk.builtin.pyCheckArgs("bool", arguments, 1);
  36. if (Sk.misceval.isTrue(x)) {
  37. return Sk.builtin.bool.true$;
  38. } else {
  39. return Sk.builtin.bool.false$;
  40. }
  41. };
  42. Sk.abstr.setUpInheritance("bool", Sk.builtin.bool, Sk.builtin.int_);
  43. Sk.builtin.bool.prototype["$r"] = function () {
  44. if (this.v) {
  45. return new Sk.builtin.str("True");
  46. }
  47. return new Sk.builtin.str("False");
  48. };
  49. Sk.builtin.bool.prototype.tp$hash = function () {
  50. return new Sk.builtin.int_(this.v);
  51. };
  52. Sk.builtin.bool.prototype.__int__ = new Sk.builtin.func(function(self) {
  53. var v = Sk.builtin.asnum$(self);
  54. return new Sk.builtin.int_(v);
  55. });
  56. Sk.builtin.bool.prototype.__float__ = new Sk.builtin.func(function(self) {
  57. return new Sk.builtin.float_(Sk.ffi.remapToJs(self));
  58. });
  59. goog.exportSymbol("Sk.builtin.bool", Sk.builtin.bool);
  60. </code></pre>
  61. </article>
  62. </section>
  63. </div>
  64. <nav>
  65. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sk.abstr.iter-seqIter.html">seqIter</a></li><li><a href="Sk.builtin.bool.html">bool</a></li><li><a href="Sk.builtin.float_.html">float_</a></li><li><a href="Sk.builtin.func.html">func</a></li><li><a href="Sk.builtin.int_.html">int_</a></li><li><a href="Sk.builtin.none.html">none</a></li><li><a href="Sk.builtin.NotImplemented.html">NotImplemented</a></li><li><a href="Sk.builtin.numtype.html">numtype</a></li><li><a href="Sk.builtin.object.html">object</a></li><li><a href="Sk.builtin.seqtype.html">seqtype</a></li><li><a href="Sk.misceval.Suspension.html">Suspension</a></li></ul><h3>Namespaces</h3><ul><li><a href="Sk.html">Sk</a></li><li><a href="Sk.abstr.html">abstr</a></li><li><a href="Sk.builtin.html">builtin</a></li><li><a href="Sk.ffi.html">ffi</a></li><li><a href="Sk.misceval.html">misceval</a></li></ul>
  66. </nav>
  67. <br class="clear">
  68. <footer>
  69. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0</a> on Thu Aug 13 2015 08:14:27 GMT-0500 (CDT)
  70. </footer>
  71. <script> prettyPrint(); </script>
  72. <script src="scripts/linenumber.js"> </script>
  73. </body>
  74. </html>