0

It's ES6 syntax, that work OK for me:

import {Component} from 'react';
class A extends Component {}
class B extends A {
    // I can redeclare some methods here
}

And how implement this with ES5? I mean:

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

Could someone provide some example, please?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Pavel Eremin
  • 91
  • 3
  • 12
  • Do you mean `class B extends A`? – Henrik Andersson Sep 09 '15 at 22:32
  • yes, sorry I just fixed this typo – Pavel Eremin Sep 09 '15 at 22:34
  • Easiest way would be to use the `inherits` module on npm, I've never done this in es5 and react so you would have to try it for yourself. – Henrik Andersson Sep 09 '15 at 22:38
  • `createClass` is an entirely separate interface. If you just want inheritance from `Component` without ES6, use [`inherits`](https://www.npmjs.com/package/inherits) or just manually set up the prototype like any number of tutorials explain. If you want to use `createClass` you will have trouble because it isn't designed for that. Which do you want? – loganfsmyth Sep 10 '15 at 01:41
  • have a look at this http://stackoverflow.com/questions/2107556/how-to-inherit-from-a-class-in-javascript/2107586#2107586 – Clarkie Sep 10 '15 at 06:54
  • Here is ES6 my code that work fine => https://jsbin.com/qewele/edit?js Can somebody convert it to ES5, please? Because I still don't undestand – Pavel Eremin Sep 10 '15 at 07:51
  • This ES5 code work for me https://jsbin.com/yudigi/edit?js is it fine? What do you think? – Pavel Eremin Sep 10 '15 at 08:27
  • @PavelEremin: If you want to convert ES6 to ES5, just use a transpiler? – Bergi Sep 10 '15 at 13:17

1 Answers1

-1

my code

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";
    }
});
张立伟
  • 57
  • 4