Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何确保';这';在mocha测试中,您可以访问类属性_Javascript_Node.js_Mocha.js - Fatal编程技术网

Javascript 如何确保';这';在mocha测试中,您可以访问类属性

Javascript 如何确保';这';在mocha测试中,您可以访问类属性,javascript,node.js,mocha.js,Javascript,Node.js,Mocha.js,const expect=require(“chai”)。expect 获取x是未定义的 问题:此内部描述完成不同上下文的点,如何使x可用于此内部摩卡测试使用箭头函数()=>此…或对函数进行绑定 describe("test goes here", () => { it("sample test", () => { expect(this.x).to.be.eq(10); }); }); 在函数上使用箭头函数()=>此…或.bind describe("test

const expect=require(“chai”)。expect

获取x是未定义的

问题:内部描述完成不同上下文的点,如何使x可用于内部摩卡测试

使用箭头函数
()=>此…
对函数进行绑定

describe("test goes here", () => {
  it("sample test", () => {
    expect(this.x).to.be.eq(10);
  });
 });
在函数上使用箭头函数
()=>此…
.bind

describe("test goes here", () => {
  it("sample test", () => {
    expect(this.x).to.be.eq(10);
  });
 });

感谢更新,只是好奇箭头函数和常规函数有何不同?@user522170感谢更新,只是好奇箭头函数和常规函数有何不同?@user522170