JSFiddle - React, Tailwind, and code Playground

HTML

<p><a href="#" id="reference">Reference</a><br/><a href="#" id="bound">Bind</a></p>

JavaScript

classname = function(){}

classname.prototype = {
    method: function(){
        try {
            alert( this.othermethod() );
        } catch(e) {
            // Method doesn't exist in scope
            alert( 'Wrong scope :(');
        }
    },
    
    othermethod: function(){
        return 'hello desired scope!';
    },
    
    referenceToElement: function(elementId, functionname){
        var el = document.getElementById(elementId);
        el.onclick = this[functionname];
    },
    
    bindToElement: function(elementId, functionname){
        var el = document.getElementById(elementId);
        el.onclick = this[functionname].bind(this);
    }
}

var instance = new classname();
instance.referenceToElement('reference', 'method');
instance.bindToElement('bound', 'method');