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

勘误 #212

Open
wants to merge 2 commits into
base: gh-pages
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
2 changes: 1 addition & 1 deletion oop/prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ B.print === A.print // true
上面代码中,`Object.create`方法在`A`的基础上生成了`B`。此时,`A`就成了`B`的原型,`B`就继承了`A`的所有属性和方法。这段代码等同于下面的代码。

```javascript
var A = function () {};
var A = {};
A.prototype = {
print: function () {
console.log('hello');
Expand Down
2 changes: 1 addition & 1 deletion oop/this.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ print() // Uncaught TypeError: this is not a Date object.

上面代码中,我们将`d.getTime`方法赋给变量`print`,然后调用`print`就报错了。这是因为`getTime`方法内部的`this`,绑定`Date`对象的实例,赋给变量`print`以后,内部的`this`已经不指向`Date`对象的实例了。

`bind`方法可以解决这个问题,让`log`方法绑定`console`对象。
`bind`方法可以解决这个问题,让`getTime`方法绑定`d`对象。

```javascript
var print = d.getTime.bind(d);
Expand Down