JSFiddle - React, Tailwind, and code Playground
by evan
JavaScript
// create a new function and assign it to a variable "Circle"
// In Javascript functions play double duty as classes (if you want)
var Circle = function (radius) {
// "this" is a magic variable that refers to the current instance
this.radius = radius;
};
// Add a function to the class (a method!)
Circle.prototype.getDiameter = function () {
return this.radius * 2;
};
// Create a new instance of "Circle"
var myCircle = new Circle(3);
// Call the method "getDiameter" on our new myCircle instance
document.body.innerHTML = myCircle.getDiameter();