From 813f4eea07f38c0c0c99cacf3a062f895d90ee49 Mon Sep 17 00:00:00 2001 From: alisa <2227642711@qq.com> Date: Wed, 20 Mar 2019 11:53:07 +0800 Subject: [PATCH] =?UTF-8?q?this=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/test.js b/test/test.js index 63a72e4..47f4d16 100644 --- a/test/test.js +++ b/test/test.js @@ -1,10 +1,12 @@ +require('should') describe('this', function () { it('setTimeout', function (done) { var obj = { say: function () { setTimeout(() => { // this 是什么?想想为什么? - this.should.equal(null) + // this.should.equal(null) + this.should.equal(obj) done() }, 0) } @@ -15,7 +17,8 @@ describe('this', function () { it('global', function () { function test() { // this 是什么?想想为什么? - this.should.equal(null) + // this.should.equal(null) + this.should.equal(global) } test() }) @@ -26,7 +29,8 @@ describe('this', function () { say: function () { function _say() { // this 是什么?想想为什么? - this.should.equal(null) + // this.should.equal(null) + this.should.equal(global) } return _say.bind(obj) }() @@ -39,7 +43,8 @@ describe('this', function () { obj.say = function () { function _say() { // this 是什么?想想为什么? - this.should.equal(null) + // this.should.equal(null) + this.should.equal(obj) } return _say.bind(obj) }()