Factory Functions - Design Patterns in JavaScript

preview_player
Показать описание

Factory functions are functions that create and return objects. A single factory can create different objects that share properties and methods.

0:00 Introduction
0:28 Object literals
0:58 Methods and the this keyword
2:45 Simple example
4:20 Realistic example

🌎 Follow me here:
Рекомендации по теме
Комментарии
Автор

Love me some Design Pattern videos. The more the merrier in my opinion. Thanks again.

chrisjames
Автор

your videos keep getting better and easy to follow. Perfect pacing imo

David.McDonald
Автор

ive been looking for this! this has been the best implementation ive seen yet. now i can make an external factory for my classes/subclasses. thanks!

luciusrex
Автор

Great video. Would love Dependency Injection explanarion with example of nest.js

jahiddev
Автор

thank you always, please also make video on dependency injection in typescript and node js

zeeshanali
Автор

Are you gonna cover all the design patterns in javascript?. Good content

samchrist
Автор

With your first example createPerson(), you pass it an object literal, thus you still have to both type out the properties and the values for the object. Would it not be more efficient to pass the values of those properties instead to the factory function, and then let the factory function assign them to the properties of the object.

For example:

function createPerson(name, age, job) {
let obj = {};
obj.name = name;
obj.age = age;
obj.job = job;

obj.presenter = function () {
return `Hello, my name is ${this.name}, I am ${this.age} years old and my job is ${this.job}`;
}

obj.setAge = function (newAge) {
this.age = newAge;
}

return obj;

}

johnnybegood
Автор

Learning from you a lot! Would it be possible to add the original versions of the files to the repository??

sharkbye
visit shbcf.ru