イベントリスナーを に追加しようとしていますが、コールバックが呼び出されないため、document
何らかの理由でイベントが発生しないように見えます:click
function NotJquery(element) {
this.element = element;
return this;
}
NotJquery.prototype.eventFired = function(event, callback) {
console.log('in NotJquery prototype');
return function (event, callback) {
element.addEventListener(event, callback, true);
};
};
var $ = function(element) {
return new NotJquery(element);
};
function Test() {
}
Test.prototype.addListener = function() {
console.log('in Test prototype');
$(document).eventFired('click', function() {
console.log('click event fired');
});
};
(function() {
var test= new Test();
test.addListener();
}());
「テスト プロトタイプ内」と「NotJquery プロトタイプ内」の両方のメッセージがコンソールに記録されますが、ドキュメント内のどこかをクリックすると、「クリック イベントが発生しました」というメッセージがコンソールに出力されません。コードの何が問題なのかわかりません。誰かがそれを機能させるためのアイデアを持っていますか?