From c270a4b22d12bdeac3b6db1b7009753801205cee Mon Sep 17 00:00:00 2001 From: liudongmiao Date: Mon, 29 Jul 2019 16:52:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=98=E4=B8=9C=E6=B7=BC-=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index 63a72e4..fe40b75 100644 --- a/test/test.js +++ b/test/test.js @@ -1,10 +1,11 @@ +const should = require('should'); describe('this', function () { it('setTimeout', function (done) { var obj = { say: function () { setTimeout(() => { - // this 是什么?想想为什么? - this.should.equal(null) + // this 是什么?想想为什么?(obj) + this.should.equal(obj) done() }, 0) } @@ -14,8 +15,8 @@ describe('this', function () { it('global', function () { function test() { - // this 是什么?想想为什么? - this.should.equal(null) + // this 是什么?想想为什么?(windows) + this.should.equal(global) } test() }) @@ -25,8 +26,8 @@ describe('this', function () { var obj = { say: function () { function _say() { - // this 是什么?想想为什么? - this.should.equal(null) + // this 是什么?想想为什么?(obj) + this.should.equal(global) } return _say.bind(obj) }() @@ -38,8 +39,8 @@ describe('this', function () { var obj = {} obj.say = function () { function _say() { - // this 是什么?想想为什么? - this.should.equal(null) + // this 是什么?想想为什么?(obj) + this.should.equal(obj) } return _say.bind(obj) }()