“Every line of code should appear to be written by a single person, no matter the number of contributors.” —@mdo
- 避免在 CSS 使用 HTML 标签选择器
| const URL = "http://helloworld.com?user=Jack&pwd=123456&hobby=read"; | |
| const RE = /(\?|\&)([^=]+)\=([^&]+)/g; | |
| let paramsObject = {}; | |
| URL.replace(RE, (match, p1, p2, p3) => { | |
| paramsObject[p2] = p3; | |
| }); | |
| console.log(paramsObject); | |
| // will be { user: 'Jack', pwd: '123456', hobby: 'read' } |
| function randomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1) + min); | |
| } |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>手机横屏友好提示</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
| </head> | |
| <body> |
“Every line of code should appear to be written by a single person, no matter the number of contributors.” —@mdo
| document.querySelectorAll('*').forEach( | |
| function(domTarget) { | |
| domTarget.addEventListener('click', function(e) { | |
| console.log(e.target); | |
| e.stopPropagation(); | |
| }); | |
| } | |
| ); |
| // 适配 AMD 和 CMD 的模块化规范 | |
| ;(function(factory){ | |
| if (typeof define === 'function' && define.amd) { | |
| // AMD | |
| define(['jquery'], factory); | |
| } else if (typeof exports === 'object') { | |
| // CommonJS | |
| factory(require('jquery')); | |
| } else { | |
| // Browser globals |
| // about assign : | |
| // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign | |
| // 对象的扩展, 本质上是一次复制操作, 将新增的属性或者方法 copy 到一个新的对象中 | |
| var _extends = Object.assign || function(target) { | |
| for (var i = 1; i < arguments.length; i++) { | |
| var source = arguments[i]; | |
| for (var key in source) { // 遍历传入的对象的属性 | |
| if (Object.prototype.hasOwnProperty.call(source, key)) { // 只操作该实例上的属性和方法, 避免循环原型 | |
| target[key] = source[key]; | |
| } |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Drag 实例</title> | |
| <style type="text/css"> | |
| #box1, | |
| #box2 { | |
| width: 100px; | |
| height: 100px; |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| <style id="jsbin-css"> | |
| .ellipsis-clamp { | |
| line-height: 20px; | |
| max-height: 40px; |