JSFiddle - React, Tailwind, and code Playground
by filmgrvin
HTML
<button id='btn'>
Click Me!
</button>
JavaScript
class Student {
constructor(name, uni) {
this.name = name;
this.uni = uni;
console.log('[0]: ' + name + ' attends ' + uni);
}
getInfo() {
return '[1]: ' + this.name + ' attends ' + this.uni;
}
printInfo() {
console.log('[2]: ' + this.name + ' attends ' + this.uni);
}
}
let btn = document.getElementById('btn');
btn.onclick = function() {
//[0]: Prints info to the console every time a new student object is created
let george = new Student('george', 'MIT');
//[1]: Uses returned data from the student object (via getInfo(), and prints it on demand).
console.log(george.getInfo());
//[2]: Prints/logs to console every time the function is called.
george.printInfo();
}