2014-12-29 1 views
1

Underscore _.compose 메서드를 사용하면 컴포지션에서 개체 메서드를 호출하고 호출되는 메서드를 소유하는 개체에 컨텍스트를 설정할 수 있습니까? ObjectOne.methodName()가 실행되면Underscore.compose에서 개체 메서드 호출

example: function(data) { 
    return _.compose(
    ObjectOne.methodName, 
    ObjectTwo.methodName 
)(data); 
} 

, 나는 ObjectOnethis를 원한다. 그러나 두 메서드 호출 모두에서 컨텍스트로 Window을 얻게됩니다. 이

example: function(data) { 
    return _.compose(
    ObjectOne.methodName.bind(ObjectOne), 
    ObjectTwo.methodName.bind(ObjectTwo) 
)(data); 
} 

bind 전화와 같은

답변

2

사용 Function.prototype.bind, 당신은 컨텍스트 객체로 전달하는 인수와 함께, 새로운 함수 객체를 반환합니다.

+0

신속하게 응답 해 주셔서 감사드립니다. 잠시 후 받아 들일 것입니다. – cantera