Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"homepage": "https://github.com/FE-star/exercise4#readme",
"devDependencies": {
"mocha": "^3.5.0",
"should": "^11.2.1"
}
}
12 changes: 8 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)
//obj
this.should.equal(obj)
done()
}, 0)
}
Expand All @@ -15,7 +16,8 @@ describe('this', function () {
it('global', function () {
function test() {
// this 是什么?想想为什么?
this.should.equal(null)
//node下global
this.should.equal(global)
}
test()
})
Expand All @@ -26,8 +28,9 @@ describe('this', function () {
say: function () {
function _say() {
// this 是什么?想想为什么?
this.should.equal(null)
this.should.equal(global)
}
//此处obj为undefined
return _say.bind(obj)
}()
}
Expand All @@ -39,8 +42,9 @@ describe('this', function () {
obj.say = function () {
function _say() {
// this 是什么?想想为什么?
this.should.equal(null)
this.should.equal(obj)
}
//硬绑定
return _say.bind(obj)
}()
obj.say()
Expand Down