Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
@Vectormike
Vectormike / class_syntax.js
Last active April 19, 2021 15:15
JavaScript class syntax
let Person = class {
constructor(name, age) {
this.name = name;
this.age = age;
}
speak() {
return `Hello, my name is ${this.name} and I am ${this.age}`
}
}
let victor = new Person('Victor', 23);
console.log(victor.speak());
let Work = class extends Person {
constructor(name, age, work) {
super(name, age);
this.work = work
}
getInfo() {
return `Hey! It's ${this.name}, I am age ${this.age} and work for ${this.work}.`
}
}
let Person = function(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.speak = function() {
return `Hello, my name is ${this.name} and I am ${this.age}`
}
let victor = new Person(`Victor`, 23)
let Work = function(name, age, work) {
Person.call(this, name, age);
this.work = work;
}
Object.setPropertyOf(Work.prototype, Person.prototype);
Work.prototype.getInfo = function() {
return `Hey! It's ${this.name}, I am age ${this.age} and work for ${this.work}.`
}
let alex = new Work("Alex", 40, 'SessionStack');
console.log(alex.getInfo());
const sayHello = function(name) {
return `Hello ${name}`;
}
sayHello('Victor');
# => Hello Victor
let surname = 'Jonah';
const sayHi = function() {
return `Hi ${surname}`;
}
const sayHi = function(surname) {
return `Hi ${surname}`;
}