【JavaScript】外掛程式參數的寫法

來源:互聯網
上載者:User

標籤:origin   ram   寫法   push   original   實現   ==   new   eof   

就是實現複製的一個過程

(function() {    var Explode = function(container, params) {        ‘use strict‘;        var n = this;        if(!(this instanceof Explode)) return new Explode(container, params);        var defaults = {            img: ‘chi2.png‘,            type: 1        };        params = params || {};    /*有參數傳遞進來賦給params,沒有為空白*/        var originalParams = {};  /*備份傳進來的params*/        for(var param in params) {  /*遍曆params*/            if(typeof params[param] === ‘object‘) {  /*如果是對象,繼續遍曆該對象,再賦值*/                originalParams[param] = {};                for(var deepParam in params[param]) {                    originalParams[param][deepParam] = params[param][deepParam];                }            } else {  /*不是對象,直接賦值*/                originalParams[param] = params[param];            }        };        for(var def in defaults) {   /*遍曆預設的參數,如果傳入的參數沒有定義到,則把預設值加進來,若已定義,則預設值沒用*/            if(typeof params[def] === ‘undefined‘) {  /*比如:如果params[img]沒有定義,則使用預設值*/                params[def] = defaults[def];            } else if(typeof params[def] === ‘object‘) {                for(var deepDef in defaults[def]) {                    if(typeof params[def][deepDef] === ‘undefined‘) {                        params[def][deepDef] = defaults[def][deepDef];                    }                }            }        };        n.params = params;        n.originalParams = originalParams;         n.container = typeof container === ‘string‘ ? document.querySelectorAll(container) : container;        if(!n.container || (n.container.length && n.container.length == 0)) return; /*沒有container直接return*/        if(n.container.length && n.container.length > 1) { /*有container且個數大於1*/            var s = [];            for(var i = 0; i < n.container.length; i++) {                s.push(new Explode(n.container[i], params));            };            return s;        };        n.container = n.container[0] || n.container;   /*有且僅有一個container*/})() 

 

【JavaScript】外掛程式參數的寫法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.