Advertisement
Guest User

ES6 inheriting from classical prototypical class

a guest
Nov 24th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Options: --debug --source-maps
  2. var f = a => {
  3.     return a + 1;
  4. };
  5.  
  6.  
  7. // Classic javascript prototypical style
  8. function BaseTest(a) {
  9.   this.a = a;
  10. }
  11.  
  12. BaseTest.prototype.go = function(a) {
  13.   this.a = a;
  14. }
  15.  
  16. // ES6 stype  - extending a classical prototypical class
  17. class Test extends BaseTest {
  18.   constructor(a) {
  19.     super(a);
  20.   }
  21.  
  22.   dostuff(f) {
  23.     return f + this.a;
  24.   }
  25.  
  26.   static green() {
  27.     return "green";
  28.   }
  29. }
  30.  
  31.  
  32. f = new Test(22);
  33.  
  34. console.log(f.a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement