其他分享
首页 > 其他分享> > 一个贴近实际开发原型链继承的l例子

一个贴近实际开发原型链继承的l例子

作者:互联网

function DomElement(id){
    this.dom = document.getElementById(id);
}
DomElement.prototype.html = function (val){
    var ele = this.dom
    if (val) {
        ele.innerHTML = val
        return this
    }else{
        return ele.innerHTML
    }
}
DomElement.prototype.on = function (type,fn){
    vae ele = this.dom
    ele.addEventListener(type,fn)
    return this
}
var div1 = new DomElement('div1')
console.log(div1.html());
div1.html('<p>这是一段文字</p>').on('click',function(){
    console.log('clicked')
})

标签:function,val,DomElement,html,ele,例子,原型,贴近,div1
来源: https://www.cnblogs.com/mushitianya/p/10652016.html