JS literal object-oriented access report not a function

var page={
    init:function(){
        this.initEvents()
    },
    bindEvent: function (target, type, name) {
        $(target).bind(type, function (e) {
            e.preventDefault();
            name(e)
            })
    },
    initEvents: function () {
        this.bindEvent(".pic-egg1", "click", this.showDiag)
        this.bindEvent(".pic-egg2", "click", this.showDiag)
    },
    showDiag: function () {
        this.hideDiag()
    },
    hideDiag:function(){
        console.log("")
    }
}

Controller reports this error

hideDiag is not a function

Jan.12,2022

function is not functiong


are you sure? The intact copy can run


you bind events in sublim. When showDiag callback, this is no longer page. The mobile phone replied, "I don't remember much about the specific solution. Search for


about how js delivers this and so on." eventHandler in

$('- sharpfoo') .bind (event, eventHandler) points to the dom element itself represented by the -sharpfoo selector, so there is an error of xx is not function .

to solve the problem, it's easy to use the bind , apply or call binding methods to the page object.

Menu