8000 Factory method · HowProgrammingWorks/Factory@2ef21cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ef21cf

Browse files
committed
Factory method
1 parent 2689aaf commit 2ef21cf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

JavaScript/5-method.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
class Person {
4+
constructor(name) {
5+
this.name = name;
6+
}
7+
static factory(name) {
8+
return new Person(name);
9+
}
10+
}
11+
12+
// Usage
13+
14+
const p1 = new Person('Marcus');
15+
console.dir({ p1 });
16+
17+
const p2 = Person.factory('Marcus');
18+
console.dir({ p2 });

0 commit comments

Comments
 (0)
0