2016-11-10 4 views
0

현재 var에는 hook의 개체가 할당되어 있습니다. 나는 이것을 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. 
    }, 

}; 

가 어떻게 아직/할당하는 다른 후크 및 테스트 케이스 (I 모카를 사용하고 있습니다) 내에서 참조 let으로 변경할 수 있습니다.

답변

0

사용

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

이 답장을 보내 주셔서 감사 this.parameter . 'test' 함수 내에서'tc' 객체 안에있는 매개 변수를 어떻게 참조 할 수 있습니까? – Ben

+0

이런 말 하시겠습니까? 'test : function() { return this.tc.param; }' –

+0

종류입니다. 'test'내에서'tc' 객체의 매개 변수를 다른 함수로 전달하고 싶습니다. 마찬가지로 :'browser.page.function (tc.parameter, tc.anotherParameter);' – Ben