jQuery event return to variable function

by Adi Jaya

HTML

<button class="demo" data-param="open">open</button>
<button class="demo" data-param="close">close</button>
<button class="demo" data-param="hello">Test not defined</button>

JavaScript

var mydata = {
    open: function() {
        alert("open");
    },
    close: function() {
        alert("close");
    }
};

$(document).on("click", ".demo", function() {
    var x = $(this).attr("data-param");
    if(x) {
        if(typeof mydata[x] == "function") {
            return mydata[x].call(this);
        } else {
            alert("Data [" + x + "] not defined");
        }
    } else {
        alert("Missing attribute [data-param]");
    }
});