function DivClass() { } DivClass.prototype={ width:50, height:50, backgroundColor:"red", createDiv:function () { var div=document.createElement("div"); div.style.width=this.width+"px"; div.style.height=this.height+"px"; div.obj=this; div.style.backgroundColor=this.backgroundColor; div.addEventListener("click",this.clickHandler); return div }, clickHandler:function (e) { Data.sum=1 console.log(this.obj,e.currentTarget) } }; function InputClass() { } InputClass.prototype={ createInput:function () { var text=document.createElement("input"); text.type="text"; text.obj=this; text.addEventListener("blur",this.blurHandler); return text }, blurHandler:function (e) { Data.sum=Number(this.value) console.log(this.obj,e.currentTarget) } }; var Data=function () { var _sum=0; return{ set sum(value){ if(isNaN(Number(value))) return; _sum+=Number(value); console.log(_sum) }, get sum(){ return _sum } } }();
js 对象中this ,以及访问器 setter,getter js文件
最新推荐文章于 2023-12-11 22:08:40 发布