Skip to content

Commit

Permalink
follow up recent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sjfkai committed Feb 22, 2016
1 parent 9043061 commit 5f7c81e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
26 changes: 26 additions & 0 deletions _posts/zh_CN/2016-02-04-assignment-shorthands.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ n --; n = n - 1;

````

### `++``--` 操作符

对于`++`操作符有些特殊。最好用下面的例子解释一下:

````javascript
var a = 2;
var b = a++;
// 现在 a == 3 b == 2
````

`a++`做了如下工作:
1. 返回`a`的值
2. `a`增加1

但是如果我们想让值先增加呢?这也很容易:

````javascript
var a = 2;
var b = ++a;
// 现在a和b都是3
````

看明白了吗?我将操作符放在了参数_前面_

`--`操作符除了使值减小外,其他功能是类似的。

### If-else (使用三元运算符)

我们平时会这样写:
Expand Down
2 changes: 1 addition & 1 deletion _posts/zh_CN/2016-02-11-preventing-unapply-attacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories:
- zh_CN
---

重写内置对象的原型方法,攻击者可以重写代码达到暴漏和修改已绑定参数的函数。这在es5的方法实现`polyfill`时是一个严重的安全漏洞
重写内置对象的原型方法,外部代码可以通过重写代码达到暴漏和修改已绑定参数的函数。这在es5的方法下使用`polyfill`时是一个严重的安全问题

```js
// bind polyfill 示例
Expand Down
10 changes: 5 additions & 5 deletions _posts/zh_CN/2016-02-15-detect-document-ready-in-pure-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories:

```js
if (document.readyState === 'complete') {
// 页面已完全加载
// 页面已完全加载
}
```

Expand All @@ -24,9 +24,9 @@ if (document.readyState === 'complete') {

```js
let stateCheck = setInterval(() => {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
// document ready
if (document.readyState === 'complete') {
clearInterval(stateCheck);
// document ready
}
}, 100);
```
Expand All @@ -37,7 +37,7 @@ let stateCheck = setInterval(() => {
```js
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
// document ready
// document ready
}
};
```
Expand Down

0 comments on commit 5f7c81e

Please sign in to comment.