JSFiddle - React, Tailwind, and code Playground

by QW01_01

JavaScript

function makeCounter(o, counterName){
	var c = 0;

    Object.defineProperty(o, counterName, {
      enumerable: false,
      configurable: false,
      get:function(){
          return c++;
      }
    });

}

makeCounter(this, 'counter');

counter;
counter;
counter;

console.log(counter);