<!DOCTYPE html>
<html>
<head>
<title>qqq</title>
<meta charset="utf-8"/>
</head>
<body>
<button>点击</button>
<script type = "text/javascript">
function Monkey(options){
this.dom = options.dom
}
Monkey.prototype.entry = function(){
this.dom.addEventListener('click',this.logic.bind(this),false);
}
Monkey.prototype.logic = function(){
this.dom.removeEventListener('click',this.logic);
console.log('ppp');
}
var btn = document.querySelector('button');
var monkey = new Monkey({
dom:btn
});
monkey.entry();
</script>
</body>
</html>
所有的代码都在这。我想要实现的是打印一次'ppp'。事实却是打印多次'ppp'。
相关分类