diff --git a/_posts/zh_CN/2016-02-04-assignment-shorthands.md b/_posts/zh_CN/2016-02-04-assignment-shorthands.md index 66405043..6c15db6c 100644 --- a/_posts/zh_CN/2016-02-04-assignment-shorthands.md +++ b/_posts/zh_CN/2016-02-04-assignment-shorthands.md @@ -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 (使用三元运算符) 我们平时会这样写: diff --git a/_posts/zh_CN/2016-02-11-preventing-unapply-attacks.md b/_posts/zh_CN/2016-02-11-preventing-unapply-attacks.md index fa008430..9f95f510 100644 --- a/_posts/zh_CN/2016-02-11-preventing-unapply-attacks.md +++ b/_posts/zh_CN/2016-02-11-preventing-unapply-attacks.md @@ -11,7 +11,7 @@ categories: - zh_CN --- -重写内置对象的原型方法,攻击者可以重写代码达到暴漏和修改已绑定参数的函数。这在es5的方法实现`polyfill`时是一个严重的安全漏洞。 +重写内置对象的原型方法,外部代码可以通过重写代码达到暴漏和修改已绑定参数的函数。这在es5的方法下使用`polyfill`时是一个严重的安全问题。 ```js // bind polyfill 示例 diff --git a/_posts/zh_CN/2016-02-15-detect-document-ready-in-pure-js.md b/_posts/zh_CN/2016-02-15-detect-document-ready-in-pure-js.md index 04f9bf60..9478b36e 100644 --- a/_posts/zh_CN/2016-02-15-detect-document-ready-in-pure-js.md +++ b/_posts/zh_CN/2016-02-15-detect-document-ready-in-pure-js.md @@ -15,7 +15,7 @@ categories: ```js if (document.readyState === 'complete') { - // 页面已完全加载 + // 页面已完全加载 } ``` @@ -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); ``` @@ -37,7 +37,7 @@ let stateCheck = setInterval(() => { ```js document.onreadystatechange = () => { if (document.readyState === 'complete') { - // document ready + // document ready } }; ```