Live Note

Remain optimistic

parseInt 中塞 number

1
2
parseInt(0.000001) // 0
parseInt(0.0000001) // 1

为什么会得到这样的结果?

  1. parseInt(arg: string):接收的是一个string变量。
  2. 0.0000001转成string会变为1e-7
  3. parseInt('1e-7')结果为1

所以要截取小数,最好还是使用Math.trunc(n)

Factory

缺点:对象无法区分,所有的实例指向一个原型

1
2
3
4
5
6
7
8
9
10
11
12
13
function Person(name) {
let o = new Object()
o.name = name
o.getName = function () {
return this.name
}

return o
}

let person = new Person("Edward")
console.log(person instanceof Person) // false
console.log(person instanceof Object) // true
Read more »

Functional Programming

经过这几天的了解,越觉得 FP 十分有趣
给个例子:

1
2
3
4
5
6
7
8
// a simple function
function add(a, b) {
return a + b
}
/// the same as
let add = function (a, b) {
return a + b
}

在 ES6 中,存在着箭头函数。所以上面的函数可以写成这个形式:

1
let add = (a, b) => a + b
Read more »

同源策略

  • 同源策略(MDN 解释):限制从一个源加载的文档或脚本如何与来自另一个源的资源进行交互。这是一个用于隔离潜在恶意文件的关键的安全机制。
  • 源:协议、域名、端口。
  • 限制:无法获取 Cookie 、 LocalStorage 和 IndexDB ,无法操作 dom ,不能发送 Ajax 。
Read more »

.gitignore 文件的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Numerous always-ignore extensions

_.bak
_.patch
_.diff
_.err

# temp file for git conflict merging

_.orig
_.log
_.rej
_.swo
_.swp
_.zip
_.vi
_~
_.sass-cache
_.tmp.html
\*.dump

# OS or Editor folders

.DS*Store
.*_
.cache
.project
.settings
.tmproj
_.esproj
_.sublime-project
_.sublime-workspace
nbproject
thumbs.db
\*.iml

# Folders to ignore

.hg
.svn
.CVS
.idea
node_modules/
jscoverage_lib/
bower_components/
dist/