front-end tips

arguments转数组

1
let args = Array.prototype.slice.call(arguments);

判断是否是Generator

1
2
3
4
// 来自于co,这里的判断前提是一个对象,所以传入的参数名是obj
function isGenerator(obj) {
return 'function' == typeof obj.next && 'function' == typeof obj.throw;
}

npm publish

npm publish 时会将.gitignore改为.npmignore

防止 Node.js 进程崩溃

可以在 process 对象的 uncaughtException 事件上注册监听器。

1
2
3
4
5
6
7
const myEmitter = new MyEmitter();

process.on('uncaughtException', (err) => {
console.error('有错误');
});

myEmitter.emit('error', new Error('whoops!'));

min-height max-height height

height会被min-height和max-height所影响,min-height和max-height不只是设置了高度的限制,logical-height由3个属性共同决定

0.5px

demo

html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<div class="example--border"></div>

* Firefox: y
* Safari: y
* Chrome: n
* Falls back to 1px for non-Retina (no need to wrap in a media query)

## 0.5px box-shadow

<div class="example--box-shadow"></div>

* Chrome: y
* Firefox: y
* Safari: n

## linear-gradient

<div class="example--gradient"></div>

* Chrome: y
* Safari: y
* Firefox: y

css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[class^='example'] {
margin: 1em 0;
height: 1px;
}

.example--box-shadow {
box-shadow: 0 0.5px 0 blue;
}

.example--border {
border-top: 0.5px solid blue;
}

.example--gradient {
background-image: linear-gradient(to bottom, blue 0%, blue 51%, transparent 51%);
background-size: 100% 1px;
}

css triangle principle

Node Module Wapper

1
2
3
(function (exports, require, module, __filename, __dirname) {
// 你的模块代码实际上在这里
});