<body>
<div id="haha">
123
</div>
<script>
Object.prototype.bind=function(e,fun){
try{
this.addEventListener(e,fun,false);
}
catch(error){
this.attachEvent('on'+e,fun);
}
}Object.prototype.unbind=function(e,fun){
try{
this.removeEventListener(e,fun,false);
}
catch(error){
this.detachEvent('on'+e,fun);
}
}var haha=document.getElementById("haha");haha.bind("click",function(){
alert("hello");
});
</script>
</body>
看看JQ的链式调用原理就知道了,内部做一个构造函数包装DOM元素,接着返回这个对象的实例。