Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. //Classes Properties, Methods (Arrow function Syntax)
  12.  
  13. //ES6
  14. // class Human {
  15. // constructor() {
  16. // this.gender = 'male';
  17. // }
  18.  
  19. // printGender() {
  20. // console.log(this.gender);
  21. // }
  22. // }
  23.  
  24. //ES7 - Requires ES6/Babel transpilation
  25.  
  26. 'use strict';
  27.  
  28. var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
  29.  
  30. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  31.  
  32. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  33.  
  34. var Human = function Human() {
  35. var _this = this;
  36.  
  37. _classCallCheck(this, Human);
  38.  
  39. this.gender = 'male';
  40.  
  41. this.printGender = function () {
  42. console.log(_this.gender);
  43. };
  44. }
  45.  
  46. //ES6
  47. // class Person extends Human {
  48. // constructor() {
  49. // super();
  50. // this.name = 'Rajeev';
  51. // }
  52.  
  53. // printName() {
  54. // console.log(this.name);
  55. // }
  56. // }
  57.  
  58. //ES7
  59.  
  60. ;
  61.  
  62. var Person = (function (_Human) {
  63. _inherits(Person, _Human);
  64.  
  65. function Person() {
  66. var _this2 = this;
  67.  
  68. _classCallCheck(this, Person);
  69.  
  70. _get(Object.getPrototypeOf(Person.prototype), 'constructor', this).apply(this, arguments);
  71.  
  72. this.name = 'Rajeev';
  73. this.gender = 'female';
  74.  
  75. this.printName = function () {
  76. console.log(_this2.name);
  77. };
  78. }
  79.  
  80. return Person;
  81. })(Human);
  82.  
  83. var person = new Person();
  84.  
  85. person.printName();
  86. person.printGender();
  87. </script>
  88.  
  89.  
  90.  
  91. <script id="jsbin-source-javascript" type="text/javascript">//Classes Properties, Methods (Arrow function Syntax)
  92.  
  93. //ES6
  94. // class Human {
  95. // constructor() {
  96. // this.gender = 'male';
  97. // }
  98.  
  99. // printGender() {
  100. // console.log(this.gender);
  101. // }
  102. // }
  103.  
  104. //ES7 - Requires ES6/Babel transpilation
  105.  
  106. class Human {
  107. gender = 'male';
  108.  
  109. printGender = () => {
  110. console.log(this.gender )
  111. }
  112. }
  113.  
  114.  
  115. //ES6
  116. // class Person extends Human {
  117. // constructor() {
  118. // super();
  119. // this.name = 'Rajeev';
  120. // }
  121.  
  122. // printName() {
  123. // console.log(this.name);
  124. // }
  125. // }
  126.  
  127. //ES7
  128.  
  129. class Person extends Human {
  130. name = 'Rajeev';
  131. gender = 'female';
  132.  
  133. printName = () => {
  134. console.log(this.name);
  135. }
  136. }
  137.  
  138. const person = new Person();
  139.  
  140. person.printName();
  141. person.printGender();</script></body>
  142. </html>
Add Comment
Please, Sign In to add comment