Skip to content
Open
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
9 changes: 5 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ describe('this', function () {
say: function () {
setTimeout(() => {
// this 是什么?想想为什么?
this.should.equal(null)
// 箭头函数的this会捕获其所在(即定义的位置)上下文的this值,而当前上下文的this正是obj
this.should.equal(obj)
done()
}, 0)
}
Expand All @@ -15,7 +16,7 @@ describe('this', function () {
it('global', function () {
function test() {
// this 是什么?想想为什么?
this.should.equal(null)
this.should.equal(global)
}
test()
})
Expand All @@ -26,7 +27,7 @@ describe('this', function () {
say: function () {
function _say() {
// this 是什么?想想为什么?
this.should.equal(null)
this.should.equal(global)
}
return _say.bind(obj)
}()
Expand All @@ -39,7 +40,7 @@ describe('this', function () {
obj.say = function () {
function _say() {
// this 是什么?想想为什么?
this.should.equal(null)
this.should.equal(obj)
}
return _say.bind(obj)
}()
Expand Down