我正在挖掘React.js
來源,這是我目前正在嘗試瞭解。什麼時候是`React.createClass({})()`調用
var ReactClass = {
/*
* @param {object} spec Class specification (which must define `render`).
* @return {function} Component constructor function.
* @public
*/
createClass: function(spec) {
var Constructor = function(props, context) {
// ...
this.props = props;
this.context = context;
this.state = null;
// ReactClasses doesn't have constructors. Instead, they use the
// getInitialState and componentWillMount methods for initialization.
var initialState = this.getInitialState ? this.getInitialState() : null;
// ...
this.state = initialState;
};
Constructor.prototype = new ReactClassComponent();
Constructor.prototype.constructor = Constructor;
// ...
mixSpecIntoComponent(Constructor, spec);
// ...
return Constructor; // <--- Who calls this?
},
// ...
};
當調用React.createClass({})
你得到Constructor
函數有兩個參數props, context
。
這個函數/方法叫做什麼,I.e.誰在做實際的React.createClass({})(someProps, someContext)
?
好,只要你* *實例化一個'新MyReactClass'它被稱爲'無功研究所=新的組件(publicProps,publicContext)之外 – Bergi
@Bergi;'我只是不能在源代碼任意找到它。 .. –
你在找哪個來源?我希望這些用戶定製的類可以從應用程序代碼中調用,而不是從庫代碼中調用。 – Bergi