class StockList extends Component { constructor(...args) { super(...args); this.state = { stockList: [], showStockList: false, showFluctuation :args[0].showFluctuation || false, //是否顯示漲跌額那一列 sortedHeader:args[0].sortedHeader && true, //是否顯示漲跌額那一列 }; } }
以上代碼是es6建立組件的方式,該段代碼建立了StockList組件,在StockList實例化的時候,以下所示:es6
<StockList theme="white" showFluctuation stockList={list} isEmptyList={false} />
constructor中的參數args含有這些屬性,也就是this
args[0] = { theme: "white", showFluctuation, stockList, isEmptyList }