diff --git a/package.json b/package.json index dcdf033..193bf1a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "homepage": "https://github.com/FE-star/exercise4#readme", "devDependencies": { + "mocha": "^3.5.0", "should": "^11.2.1" } } diff --git a/test/test.js b/test/test.js index 63a72e4..1fc775c 100644 --- a/test/test.js +++ b/test/test.js @@ -4,7 +4,8 @@ describe('this', function () { say: function () { setTimeout(() => { // this 是什么?想想为什么? - this.should.equal(null) + //obj + this.should.equal(obj) done() }, 0) } @@ -15,7 +16,8 @@ describe('this', function () { it('global', function () { function test() { // this 是什么?想想为什么? - this.should.equal(null) + //node下global + this.should.equal(global) } test() }) @@ -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) }() } @@ -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()