Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from wangdoc:master #48

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .github/workflows/wangdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@main
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: 'latest'
- name: Install dependencies
run: npm install
- name: Build pages
run: npm run build
- name: Deploy to website
uses: JamesIves/github-pages-deploy-action@3.7.1
uses: JamesIves/github-pages-deploy-action@v4
with:
GIT_CONFIG_NAME: wangdoc-bot
GIT_CONFIG_EMAIL: [email protected]
REPOSITORY_NAME: wangdoc/website
ACCESS_TOKEN: ${{ secrets.WANGDOC_BOT_TOKEN }}
BASE_BRANCH: master
BRANCH: master # The branch the action should deploy to.
FOLDER: dist # The folder the action should deploy.
TARGET_FOLDER: dist/javascript
CLEAN: true # Automatically remove deleted files from the deploy branch
COMMIT_MESSAGE: update from JavaScript tutorial
git-config-name: wangdoc-bot
git-config-email: [email protected]
repository-name: wangdoc/website
token: ${{ secrets.WANGDOC_BOT_TOKEN }}
branch: master # The branch the action should deploy to.
folder: dist # The folder the action should deploy.
target-folder: dist/javascript
clean: true # Automatically remove deleted files from the deploy branch
commit-message: update from JavaScript tutorial

2 changes: 1 addition & 1 deletion docs/bom/window.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ var start = null;
function step(timestamp) {
if (!start) start = timestamp;
var progress = timestamp - start;
// 元素不断向左移,最大不超过200像素
// 元素不断向右移,最大不超过200像素
element.style.left = Math.min(progress / 10, 200) + 'px';
// 如果距离第一次执行不超过 2000 毫秒,
// 就继续执行动画
Expand Down
14 changes: 7 additions & 7 deletions docs/oop/this.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,19 +679,19 @@ Array.prototype.slice.apply({length: 1}) // [undefined]
前面的按钮点击事件的例子,可以改写如下。

```javascript
var o = new Object();
var obj = new Object();

o.f = function () {
console.log(this === o);
var func = function () {
console.log(this === obj);
}

var f = function (){
o.f.apply(o);
// 或者 o.f.call(o);
var handler = function (){
func.apply(obj);
// 或者 f.call(obj);
};

// jQuery 的写法
$('#button').on('click', f);
$('#button').on('click', handler);
```

上面代码中,点击按钮以后,控制台将会显示`true`。由于`apply()`方法(或者`call()`方法)不仅绑定函数执行时所在的对象,还会立即执行函数,因此不得不把绑定语句写在一个函数体内。更简洁的写法是采用下面介绍的`bind()`方法。
Expand Down
4 changes: 2 additions & 2 deletions docs/types/null-undefined-boolean.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ undefined == null

既然含义与用法都差不多,为什么要同时设置两个这样的值,这不是无端增加复杂度,令初学者困扰吗?这与历史原因有关。

1995年 JavaScript 诞生时,最初像 Java 一样,只设置了`null`表示"无"。根据 C 语言的传统,`null`可以自动转为`0`。
1995年 JavaScript 诞生时,最初像 Java 一样,只设置了`null`表示“无”。根据 C 语言的传统,`null`可以自动转为`0`。

```javascript
Number(null) // 0
Expand All @@ -46,7 +46,7 @@ Number(null) // 0

但是,JavaScript 的设计者 Brendan Eich,觉得这样做还不够。首先,第一版的 JavaScript 里面,`null`就像在 Java 里一样,被当成一个对象,Brendan Eich 觉得表示“无”的值最好不是对象。其次,那时的 JavaScript 不包括错误处理机制,Brendan Eich 觉得,如果`null`自动转为0,很不容易发现错误。

因此,他又设计了一个`undefined`。区别是这样的:`null`是一个表示“空”的对象,转为数值时为`0`;`undefined`是一个表示"此处无定义"的原始值,转为数值时为`NaN`。
因此,他又设计了一个`undefined`。区别是这样的:`null`是一个表示“空”的对象,转为数值时为`0`;`undefined`是一个表示此处无定义的原始值,转为数值时为`NaN`。

```javascript
Number(undefined) // NaN
Expand Down
6 changes: 6 additions & 0 deletions docs/types/number.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ NaN * 32 // NaN
NaN / 32 // NaN
```

但是,ES6 引入指数运算符(`**`)后,出现了一个例外。

```javascript
NaN ** 0 // 1
```

### Infinity

**(1)含义**
Expand Down
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
"server": "loppo server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"husky": {
"hooks": {
"pre-push": "npm update"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/wangdoc/javascript-tutorial.git"
Expand All @@ -35,9 +30,8 @@
},
"homepage": "https://github.com/wangdoc/javascript-tutorial",
"dependencies": {
"gh-pages": "5.x",
"husky": "^4.3.8",
"gh-pages": "6.x",
"loppo": "^0.6.24",
"loppo-theme-wangdoc": "^0.6.1"
"loppo-theme-wangdoc": "^0.7.3"
}
}