2016-11-10 60 views
0

目前,我正在使用從另一個hook分配對象的var。我想將其更改爲let,但我一直在絆倒錯誤。當超出範圍時,將對象分配給let關鍵字

當前設置:

var tc; 

module.exports = { 

    before(browser) { 
    tc = new func()(x, y); // needs to be assigned here. 
    }, 

    'Test': function (browser) { 
    tc // needs to be referenced here too. 
    }, 

}; 

我怎樣才能將其更改爲let尚未指派/其他掛鉤和測試案例(我使用的是摩卡)內引用它。

回答

0

使用this.parameter

module.exports = { 

    before(browser) { 
    this.tc = new func()(x, y); // Now it's assigned to the object context. 
    }, 

    'Test': function (browser) { 
    return this.tc; // You can reference to the variable inside the object 
    }, 

}; 
+0

謝謝您的答覆。如何在'test'函數內的'tc'對象內引用一個參數? – Ben

+0

你說這樣嗎? 'test:function(){ return this.tc.param; }' –

+0

的種類。在'測試'中,我想將'tc'對象的參數傳遞給另一個函數。像這樣:'browser.page.function(tc.parameter,tc.anotherParameter);' – Ben