我的印象是ES6类基本上是围绕ES5对象系统的语法糖.当我试图在没有转换器的情况下运行React时,我想我可以使用旧语法来定义从React.Component"继承"的对象"类".
var Board = function(props, state) {
var instance = {};
instance.props = props;
instance.context = state;
return(instance);
};
Board.prototype = Object.create(React.Component.prototype);
Board.prototype.render = function() {
return(
// ...stuff
)
};
Run Code Online (Sandbox Code Playgroud)
但这不起作用!
react.js:20478 Warning: Board(...): No `render` method found on the returned component instance: you may have forgotten to define `render`
react.js:6690 Uncaught TypeError: inst.render is not a function(…)
Run Code Online (Sandbox Code Playgroud)
var Board = function(props, state) {
var instance = Object.create(React.Component.prototype);
instance.props = props;
instance.context = state; …Run Code Online (Sandbox Code Playgroud)