JSFiddle - React, Tailwind, and code Playground

JavaScript

function Formatter() {
    this.format = function(char) {
        var regex = /[a-z]/i;
    
        if (regex.test(char) && typeof this[char] === 'function') {
           this[char]();
        }
    };
    
    this.x = function() {
        alert('works');
    }
}

formatter = new Formatter();

formatter.format('x');