(function(global, factory) { if (typeof global.document === 'undefined') { throw new Error('the environment must have a window Object with document !') } // 若環(huán)境存在則執(zhí)行factory factory(global); })(typeof window !== 'undefined' ? window : this, function (window) { var _mJQ = function (selector) { return new _mJQ.init(selector); } // 初始化 _mJQ.init = function(selector) { // 進(jìn)行selector匹配,比如class,attr,id等... if (selector === '#test') { const elem = document.getElementById('test') this.elem = elem return this } return this } // 讓init的原型對象指向_mJQ的原型 _mJQ.init.prototype = _mJQ.prototype = { // 功能 each: function() { // 循環(huán) }, html: function() {}, css: function (name, value) { console.log(this) this.elem.style[name] = value } } // 設(shè)置contructor指向問題 Object.defineProperty(_mJQ.prototype, 'constructor', { enumerable: false, value: _mJQ }) // 掛載到window window.$ = window.mJQ = _mJQ; })
https://github.com/clm960227/...
相關(guān)文章推薦:
svg中<marker>元素的使用及marker屬性的介紹
JavaScript設(shè)計(jì)模式之簡單介紹適配器模式
Angular表單驗(yàn)證的兩種方法介紹
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com