2016-07-02 3 views
0

내가 완벽하게 여기 정적 함수 구문과 함께 작품을 찾고 있어요 기능성 그러나, 내가 생성자 자체에 선언 된 정적 기능을 (좋아, 즉 className.staticFunction() => ... 대신 클래스 정의 자체 내에서 static staticFunction =() => ...의. 여기 정적 함수를 사용하지 않고이 고차 함수를 어떻게 다시 작성합니까?

코드입니다 I는 아래와 같이 I 생성자/함수보다는 static 구문 정의 된 정적 함수를 사용 리팩토링하려는 것을 언급하고있다.

const higherOrderFunction = another => andAnother => class extends Component { 

    static functionName = { 
    test: React.PropTypes.object 
    }; 

    constructor(props) { 
    super(props); 
    } 

    render() { 
    return <h1>Hello, World!</h1>; 
    } 
}; 

export default higherOrderFunction; 
+0

를? – Bergi

답변

1

class의 값은 생성자와 동일 function 클래스없이 정의하면됩니다 :

const higherOrderFunction = another => andAnother => Component; 

function Component() {} 

Component.functionName =() => { 
    test: React.PropTypes.object 
}; 

Component.prototype.render =() => { 
    return <h1>Hello, World!</h1>; 
} 

export default higherOrderFunction; 
당신은 캡슐화 및 인수를 사용하는 함수 본문에서 함수와 멤버 정의를 포장 할 수 있습니다

: 당신은`another`와`andAnother`을 사용하는 경우

const higherOrderFunction = another => andAnother => { 
    function Component() {} 

    Component.functionName =() => { 
    test: React.PropTypes.object 
    }; 

    Component.prototype.render =() => { 
    return <h1>Hello, World! {another} and {andAnother}</h1>; 
    } 

    return Component; 
}; 

export default higherOrderFunction; 
+0

그러나 이것은 어쨌든 ES6 클래스로이를 달성 할 수 있을지 궁금합니다. – Detuned

+0

예. 함수를 정의하는 대신 방금 클래스를 정의합니다. 나중에 정적 함수를 고정시킬 수 있습니다. – DDS

관련 문제