JSFiddle - React, Tailwind, and code Playground
by black strings
JavaScript
// use the new class key word
class Systum {
constructor(){
this.id = 1;
}
calc(){
return this.id * 5;
}
}
// createing a class like using just function
function System() {
const id = 1;
function calc(){
return id * 5;
}
//this.calc = calc;
return {
calc: calc
}
}
const s1 = new Systum();
const val = s1.calc();
console.log('calc(): ', val);
console.log('instanceof Systum:', s1 instanceof Systum);
console.log('typeof: ', typeof s1);
console.log('-----------------------------------------------');
const s2 = new System();
const val2 = s2.calc();
console.log('calc(): ', val2);
console.log('instance of System:', s2 instanceof System);
console.log('typeof: ',typeof s2);
/* console.log(typeof 'sss');
console.log(typeof 3);
console.log(typeof true); */