代码执行的问题

var a = document.querySelector(".a");
var b = document.querySelector(".b");

function Student() {
    this.bbb();
}

function add(Student) {
    Student.prototype.bbb = function() {
        this.getName();
        this.jiao();
        console.log(this);
    };
    Student.prototype.getName = function() {
        console.log(this);
        hh(a, "click", this, false);
    };
    Student.prototype.jiao = function() {
        alert("汪汪汪");
    };
}


function hh(dom, type, fn, capture) {
    dom.addEventListener(type, fn, capture);
}

add(Student);

var c = new Student();

我点击dom为什么没有响应

阅读 1.8k
3 个回答

你这是啥啊

clipboard.png

从开始到结束你事件都没给绑定上啊

你把Student传进点击事件了

//试试
hh(a, 'click', this.jiao, false);
hh(a, 'click', this, false);

这个有问题
你传this干嘛,this又不是函数,你当然调用不了了,要调用jiao

 hh(a, 'click', this.jiao, false);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题