I was going to sleep but then I came across a video of yours and binge-watched all the videos in the Tutorials playlist. And it is 3.30AM. So, awesome work!!
@DevSage4 жыл бұрын
Glad you like them!
@clingyking2774 Жыл бұрын
2 years later and I'm watching this at 0355am
@neuodev2 жыл бұрын
I happy that I "visited" DevSage!
@beastblack66544 жыл бұрын
I've been struggling to understand this, thanks a lot!
@DevSage4 жыл бұрын
You're welcome!
@ינוןאלבז-כ1ז2 жыл бұрын
very cool, thanks for shering, exellent channel!!!
@aniketpaul51184 жыл бұрын
Amazing videos. Very nice explanations. Would like you to consider making a video on composite pattern
@MrLinuxFreak Жыл бұрын
isnt this is same as bind?
@amerikan4 жыл бұрын
Overall good video, though I would just say be careful when doing Employee.prototype = { getFoo: function () { ... code ....}}; as this will overwrite the original prototype reference! It’s safer to do Employee.prototype.getFoo = function () {.....};
@DevSage4 жыл бұрын
That's actually a really good point. I hadn't even thought about that until reading this comment. Thanks
@gkarapeev3 жыл бұрын
What is the benefit of this over simply writing: devsage.salary = devsage.salary * 2; Right? We just changed the internal state of an object instance of a constructor function. What did we achieve? I'm sure there is a point to it, and it is useful in some situations. However, I didn't understand why we did it.
@SR-er6hx3 жыл бұрын
Useful for AST walking
@javascriptduniya12014 жыл бұрын
var DevSage = new Employee('DevSage',10000); console.log(DevSage.getSalary()); // 1000 function doubleSalary(DevSage){ DevSage.setSalary(DevSage.getSalary() *2) ; } doubleSalary(DevSage); console.log(DevSage.getSalary()); //2000 We can also call this way, Can you please telll me why do we need accept method here ?
@DevSage4 жыл бұрын
I suppose either way could work. I don't see any major advantage. The Visitor pattern is not very widely used/known in Javascript but in other languages there may be good reasons to use it.
@javascriptduniya12014 жыл бұрын
@@DevSage Thank you
@subrotomukherjee8571Ай бұрын
very good series
@georgidimitranov87815 жыл бұрын
Hey, greeting from Bulgaria. Thanks for making this videos. Your explaining stuff really good. My request is. Can you make videos for the PubSup and Mediator patters. ^^
@DevSage5 жыл бұрын
Greetings. Thank you for the compliment. I have a video about the mediator pattern here -> kzbin.info/www/bejne/kKbLmIKrYql6d5Y
@gkarapeev3 жыл бұрын
+1 from Bulgaria! :D
@ratias04 жыл бұрын
Thank you very much. Now it is very clear how this pattern works, but I am still a bit confused about its use case.
@traveltechtaste41 Жыл бұрын
Suppose we have a method which calculates monthly salary of employees. Now company has decided to add spot bonus for few employees. In that case we can create a modifiedSalary() function. This function will contain a variable 'spotBonus' which gets added to calculatedSalary of employees. In this way we don't need to modify existing class/ function.
@PhilanJames5 жыл бұрын
Nice tutorial. I’m trying to think about a practical use case for this. Is this scenario valid.. The Employee class is manipulated by the HR department who hires employees, logs their information and such. The ExtraSalary class is handled by the Finance department?
@DevSage5 жыл бұрын
Yeah that actually sounds like it could be a valid application
@Chris-qg6kc3 жыл бұрын
Is there a particular reason that you always do JavaScript OOP using the prototype method vs class kw? I like what you are doing -continued Success 👍🏾💯👌🏾
@yshuttle3 жыл бұрын
I went to watch this video and realized I'm watching it at the exact same time it was recorded 2 years later. 3:28 PM on December 7th
@DevSage3 жыл бұрын
😅😅
@DevSage3 жыл бұрын
Maybe it's some kind of omen
@octaviusbytes5 жыл бұрын
How do you feel about making a video on javascript prototypes?
@DevSage5 жыл бұрын
Hmm.. I will definitely consider it!
@ishdx93744 жыл бұрын
I think they are obsolete, considering that classes are introduced, and if you worry about compatibility, there's transpilers
@mfhsieh68584 жыл бұрын
@@ishdx9374 I don't think so. ES6 class is sugar syntax, it main concept is from prototype inheritance. So, it’s good to know the prototype.
@ishdx93744 жыл бұрын
@@mfhsieh6858 well, I meant that they are obsolete in a way that they aren't that interesting to a programmer any more, and JS can do some optimizations on classes because it knows what you are doing
@karthickdurai21575 жыл бұрын
Hey man great video but do you think solving this with class that came with ES6 is simpler.
@CrassCriss4 жыл бұрын
just a bit simpler :o class Employee{ constructor(name, salary){ this.name = name; this.salary = salary; } getSalary(){ return this.salary; } setSalary(salary){ this.salary = salary; } accept(visitorFunction){ // this is a reference to our Employee visitorFunction(this); } } const devChris = new Employee("Chris", 10000); console.log(devChris.getSalary()); function ExtraSalary(emp){ emp.setSalary(emp.getSalary() * 2); } devChris.accept(ExtraSalary); console.log(devChris.getSalary());
@karthickdurai21574 жыл бұрын
@@CrassCriss thanks dude, though now I have become very much comfortable with js from the time the comment was posted
@CrassCriss4 жыл бұрын
@@karthickdurai2157 haha okay, just saw the video today sorry... well..maybe its useful for someone else :)