;(function(win, lib) { var doc = win.document var docEl = doc.documentElement // 可能放在head获取不到body })(window, window['lib'] || (window['lib'] = {})); console.warn('将根据已有的meta标签来设置缩放比例'); console.info('1 2 ')
void function(factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory) } else if (typeof exprots === 'object') { factory(require('jquery')) } else { factory(jQuery) } }(function($) { console.log($) function Person = function() {} return Person }); void function(root, factory) { if (typeof module !== 'undefined' && module.exports) { module.exports = factory() } else if (typeof define === 'function' && define.amd) { define(factory) } else { root.A = factory.call(root) } }(this, function() { function Person = function() {} return Person });
参数处理
获取伪元素属性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> #box:before { content: 'jj'; color: red; } </style> </head> <body> <div id="box"></div> <script> var style = window.getComputedStyle(document.querySelector('#box'), ':before') var color = style.getPropertyValue('color') var content = style.getPropertyValue('content') console.log(color) console.log(content) </script> </body> </html>
递归
function toJson(val) { if (isArray(val)) { var array = [] for (var i = 0; i < val.length; i++) { array[i] = toJson(val[i]) } return array } else if (isObject(val)) { var obj = {} for (i in val) { if (val.hasOwnProperty(i)) { var value = val[i] obj[i] = value && value.nodeType ? value : toJson(value) } } return obj } return val }