JSFiddle - React, Tailwind, and code Playground

HTML

<div id="links"></div>

JavaScript

var A = function (j) {
      this.b = j;
  };
  var links = $("#links");
  for (var i = 0; i < 100; i++) {

      (function () {
          var a = new A(i); // a is the local variable mentioned in the question
          links.append($("<a> " + i + " </a>").click(function () {
              console.log(a.b);
              // when the <a>i</a> is clicked 99 is always printed to console
          }));
      })(i);
  }