diff --git a/package.json b/package.json index 8d356a5..db6e845 100644 --- a/package.json +++ b/package.json @@ -22,5 +22,9 @@ "devDependencies": { "mocha": "^6.0.2", "should": "^11.2.1" + }, + "dependencies": { + "mocha": "^6.2.0", + "should": "^11.2.1" } } diff --git a/test/test.js b/test/test.js index 63a72e4..f5b55c5 100644 --- a/test/test.js +++ b/test/test.js @@ -1,49 +1,48 @@ -describe('this', function () { - it('setTimeout', function (done) { +describe('this', function() { + it('setTimeout', function(done) { var obj = { - say: function () { + say: function() { setTimeout(() => { // this 是什么?想想为什么? - this.should.equal(null) + this.should.equal(obj) done() }, 0) } } obj.say() - }) + }) - it('global', function () { + it('global', function() { function test() { // this 是什么?想想为什么? - this.should.equal(null) + this.should.equal(undefined) } test() }) - - describe('bind', function () { - it('bind undefined', function () { - var obj = { - say: function () { - function _say() { - // this 是什么?想想为什么? - this.should.equal(null) - } - return _say.bind(obj) - }() - } - obj.say() - }) - - it('bind normal', function () { - var obj = {} - obj.say = function () { +}) +describe('bind', function() { + it('bind undefined', function() { + var obj = { + say: (function() { function _say() { // this 是什么?想想为什么? - this.should.equal(null) + this.should.equal(undefined) } return _say.bind(obj) - }() - obj.say() - }) + })() + } + obj.say() + }) + + it('bind normal', function() { + var obj = {} + obj.say = (function() { + function _say() { + // this 是什么?想想为什么? + this.should.equal(obj) + } + return _say.bind(obj) + })() + obj.say() }) -}) \ No newline at end of file +})