JSFiddle - React, Tailwind, and code Playground

by hajpoj

JavaScript

function Fruit(name) {
    this.name = name;
}
Fruit.prototype.formattedName = function() {
    return this.name.toUpperCase();
};
Fruit.prototype.counter = 0;
Fruit.prototype.updateCounter = function() {
    this.counter ++;
}

var apple = new Fruit("apple");
console.log(apple.formattedName());

Fruit.prototype.formattedName = function() {
    return "text";
}



var orange = new Fruit("orange");
console.log(orange.formattedName());

console.log(apple);
console.log(orange);

apple.updateCounter();
apple.updateCounter();
apple.updateCounter();
orange.updateCounter();
alert(orange.counter);
alert(apple.counter);