2015-09-09 35 views
0

它ES6語法,這項工作確定爲我擴展類?我的意思是:反應使用ES5

var React = require('react'); 
var A = React.createClass({}); 
var B = ??? 

有人可以提供一些例子嗎?

+0

你的意思是'B類擴展A'? –

+0

是的,對不起,我只是修復了這個錯字 –

+0

最簡單的方法是在npm上使用'inherits'模塊,我從來沒有在es5中做過這樣的反應,所以你必須自己嘗試。 –

回答

0

我的代碼

React.extend=function(parentClass,nprototype){ 
    var childClass=function(){}; 
    childClass.prototype=new parentClass({}); 
    for(var i in nprototype){ 
     childClass.prototype[i]=nprototype[i]; 
    } 
    return childClass; 
} 

var Parent=React.createClass({ 
    getContent:function(){ 

    }, 
    render:function(){ 
     return (
      <div>{this.getContent()}</div> 
     ); 
    } 
}); 

var Child=React.extend(Parent,{ 
    getContent:function(){ 
     return "this is child Content"; 
    } 
});