String.prototype.dogSpeak = function(){ return this + " Woof!\n"; }; const dogSpeak1 = function(s){ return s + " Woof!\n"; } let s = "We like to learn"; console.log(s.dogSpeak()); // console.log(s.dogSpeak1()); // console.log(dogSpeak1(s)); console.log("Dogs are smart".dogSpeak()); // console.log("Dogs are smart".dogSpeak1()); // console.log(dogSpeak1("Dogs are smart")); console.log(this); const pippo = function() { console.log(this); const pluto = { a: function(){ console.log(this); }, b: () => { console.log(this); } }; pluto.a(); pluto.b(); }; const a = new pippo(); /*(function(){ console.log(this); })();*/ function Video(conf = {}) { this.title = conf.title || "Hello World!"; this.seconds = conf.seconds || 10; } // Video properties and methods Video.prototype.title = "Prova"; Video.prototype.seconds = 100; Video.prototype.watch = function(x) { const s = x || this.seconds; console.log("You watched " + s + " seconds of " + this.title); }; function MusicVideo(conf = {}) { this.title = conf?.title || "Hello World!"; this.seconds = conf?.seconds || 10; this.artist = conf?.artist || "Giorgio Vivaldi"; } // Prototypal hineritance MusicVideo.prototype = new Video(); // MusicVideo further properties and methods MusicVideo.prototype.artist = "Vivaldi"; MusicVideo.prototype.play = function() { console.log("You played " + this.title + " by " + this.artist); }; const myMusicVideo = new MusicVideo({ title: "Gli spari sopra", seconds: 300, artist: "Vasco Rossi" }); // instance of MusicVideo Object console.log(myMusicVideo.title); console.log(myMusicVideo.seconds); myMusicVideo.watch(12); myMusicVideo.watch(); console.log(myMusicVideo.artist); myMusicVideo.play(); const myVideo = new Video({ title: "Gli spari sopra", seconds: 300 }); // instance of Video Object console.log(myVideo.title); console.log(myVideo.seconds); myVideo.watch(122); myMusicVideo.watch(); console.log(myVideo.artist); myVideo.play(); /*function Vehicle() {} Vehicle.prototype.drive = function(){ console.log("Vroooom"); } function Car() {} Car.prototype = new Vehicle(); Car.prototype.honk = function(){ console.log("Honk Honk"); } const myCar = new Car(); myCar.drive(); myCar.honk(); const myVehicle = new Vehicle(); myVehicle.drive(); myVehicle.honk();*/
Title | Name | Language | UNIX | When |
---|---|---|---|---|
Re: Lesson 14 05 - added regex part | Simmese | javascript | 1652598109 | 4 Days ago. |