javascript function in class code example
Example 1: javascript new function as class
function Person(name){
const birth = new Date();
this.greet = () => `Hello my name is ${name}. I was born at ${birth.toISOString()}`;
}
const joe = new Person("Joe");
joe.greet();
Example 2: javascript classes
class SayHelloTo {
name (to) {
console.log(`Hello ${to}`);
}
constructor (to) {
this.name(to);
}
}
const helloWorld = new SayHelloTo(World);
Example 3: variables in js class
constructor(){
this.foo = bar
}
Example 4: how to create class in javascript
class ClassName
{
}