?var?$?=?function?(selector)?{
????????????return?new?$.prototype.init(selector);
????????};
????????$.prototype?=?{
????????????init:?function?(selector)?{
????????????????this.el?=?document.querySelector(selector);
????????????????console.log(this)
????????????????return?this;
????????????},
????????????on:?function?(event,?fn)?{
????????????????if?(window.addEventListener)?{
????????????????????this.el.addEventListener(event,?fn,?false);
????????????????}?else?if?(window.attachEvent)?{
????????????????????this.el.attachEvent(on?+?event,?fn);
????????????????}
????????????????return?this;
????????????},
????????????attr:?function?(event,?val)?{
????????????????if?(!val)?{
????????????????????return?this.el.getAttribute(event);
????????????????}?else?{
????????????????????this.el.setAttribute(event,?val);
????????????????????return?this;
????????????????}
????????????}
????????}
????????$.prototype.init.prototype?=?$.prototype;
js鏈式寫法沒有懂 求詳細解釋一下
歐羅巴皇
2017-05-26 14:47:43