2017-03-13 2 views
0

간단한 반응 구성 요소를 렌더링 중입니다. 생성자를 사용하여 반응하는 응용 프로그램을 초기화하십시오.

는 아무도 내가가 새로운 기능 AppInitializer에 왜 대신 AppInitializer.run();

class AppInitializer { 
run() { 
    render(
     <Router history={browserHistory}> 
      <Route path="/" component={ App } > 
       <IndexRoute component={ Home } /> 
      </Route> 
      <Redirect from="*" to="/" /> 
     </Router> 
     , document.getElementById('app') 
    ); 
    } 
} 

new AppInitializer().run(); 

답변

0

runnew AppInitializer().run();, 설명 AppInitializer 클래스의 비 정적 함수입니다 수 있습니다. 그것을 호출하기 위해서는 클래스의 인스턴스를 생성해야합니다.

다음 코드 :

var a = new AppInitializer(); 
a.run(); 
:

new AppInitializer().run(); 

은 동일합니다

관련 문제