(function(global, factory) { if (typeof global.document === 'undefined') { throw new Error('the environment must have a window Object with document !') } // 若環境存在則執行factory factory(global); })(typeof window !== 'undefined' ? window : this, function (window) { var _mJQ = function (selector) { return new _mJQ.init(selector); } // 初始化 _mJQ.init = function(selector) { // 進行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() { // 循環 }, html: function() {}, css: function (name, value) { console.log(this) this.elem.style[name] = value } } // 設置contructor指向問題 Object.defineProperty(_mJQ.prototype, 'constructor', { enumerable: false, value: _mJQ }) // 掛載到window window.$ = window.mJQ = _mJQ; })
https://github.com/clm960227/...
相關文章推薦:
svg中<marker>元素的使用及marker屬性的介紹
JavaScript設計模式之簡單介紹適配器模式
Angular表單驗證的兩種方法介紹
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com