1// Javascript Function that behaves as class, with private variables
2function Person(name){
3 const birth = new Date();
4 this.greet = () => `Hello my name is ${name}. I was born at ${birth.toISOString()}`;
5}
6
7const joe = new Person("Joe");
8joe.greet(); // Hello my name is Joe. I was born at 2021-04-09T21:12:33.098Z
9// The birth variable is "inaccessible" from outside so "private"