Facebook
From Simmese, 5 Days ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 50
  1. String.prototype.dogSpeak = function(){
  2.     return this + " Woof!\n";
  3. };
  4.  
  5. const dogSpeak1 = function(s){
  6.     return s + " Woof!\n";
  7. }
  8.  
  9. let s = "We like to learn";
  10. console.log(s.dogSpeak());
  11. // console.log(s.dogSpeak1());
  12. // console.log(dogSpeak1(s));
  13.  
  14. console.log("Dogs are smart".dogSpeak());
  15. // console.log("Dogs are smart".dogSpeak1());
  16. // console.log(dogSpeak1("Dogs are smart"));
  17.  
  18.  
  19. console.log(this);
  20.  
  21. const pippo = function() {
  22.     console.log(this);
  23.  
  24.     const pluto = {
  25.         a: function(){
  26.             console.log(this);
  27.         },
  28.         b: () => {
  29.             console.log(this);
  30.         }
  31.     };
  32.  
  33.     pluto.a();
  34.     pluto.b();
  35. };
  36.  
  37. const a = new pippo();
  38.  
  39. /*(function(){
  40.     console.log(this);
  41. })();*/
  42.  
  43. function Video(conf = {}) {
  44.     this.title = conf.title || "Hello World!";
  45.     this.seconds = conf.seconds || 10;
  46. }
  47.  
  48. // Video properties and methods
  49. Video.prototype.title = "Prova";
  50. Video.prototype.seconds = 100;
  51. Video.prototype.watch = function(x) {
  52.     const s = x || this.seconds;
  53.     console.log("You watched " + s + " seconds of " + this.title);
  54. };
  55.  
  56. function MusicVideo(conf = {}) {
  57.     this.title = conf?.title || "Hello World!";
  58.     this.seconds = conf?.seconds || 10;
  59.     this.artist = conf?.artist || "Giorgio Vivaldi";
  60. }
  61.  
  62. // Prototypal hineritance
  63. MusicVideo.prototype = new Video();
  64.  
  65. // MusicVideo further properties and methods
  66. MusicVideo.prototype.artist = "Vivaldi";
  67. MusicVideo.prototype.play = function() {
  68.     console.log("You played " + this.title + " by " + this.artist);
  69. };
  70.  
  71. const myMusicVideo = new MusicVideo({
  72.     title: "Gli spari sopra",
  73.     seconds: 300,
  74.     artist: "Vasco Rossi"
  75. }); // instance of MusicVideo Object
  76.  
  77. console.log(myMusicVideo.title);
  78. console.log(myMusicVideo.seconds);
  79. myMusicVideo.watch(12);
  80. myMusicVideo.watch();
  81.  
  82. console.log(myMusicVideo.artist);
  83. myMusicVideo.play();
  84.  
  85. const myVideo = new Video({
  86.     title: "Gli spari sopra",
  87.     seconds: 300
  88. }); // instance of Video Object
  89.  
  90. console.log(myVideo.title);
  91. console.log(myVideo.seconds);
  92. myVideo.watch(122);
  93. myMusicVideo.watch();
  94.  
  95. console.log(myVideo.artist);
  96. myVideo.play();
  97.  
  98. /*function Vehicle() {}
  99. Vehicle.prototype.drive = function(){
  100.     console.log("Vroooom");
  101. }
  102.  
  103. function Car() {}
  104. Car.prototype = new Vehicle();
  105.  
  106. Car.prototype.honk = function(){
  107.     console.log("Honk Honk");
  108. }
  109.  
  110. const myCar = new Car();
  111.  
  112. myCar.drive();
  113. myCar.honk();
  114.  
  115. const myVehicle = new Vehicle();
  116.  
  117. myVehicle.drive();
  118. myVehicle.honk();*/
  119.  

Replies to Lesson 14 05 rss

Title Name Language When
Re: Lesson 14 05 - added regex part Simmese javascript 4 Days ago.