subclass: subclass is a class that extends another class. 即子类。

In ES2015, to use 'this' in subclasses, we first must call super().

Why 'this' can not be allowed before super()?

Because 'this' is uninitialized if super() is not called.

ES6 class constructors must call super() if they are subclasses. However, a subclasses does not have to have a constructor().

What super() does?

super() will call the constructor of its parent's class. (super() refers to the parent)

The difference between super() and super(props)

Call super(props) only if you want to access 'this.props' inside the constructor.

When you use super() inside the constructor, you can use 'props' to get props.

react super() and super(props)的更多相关文章

  1. 如何理解react中的super() super(props)

    class WebSite extends React.Component { constructor() { super(); this.state = { name: "菜鸟教程&quo ...

  2. react super中的props

    有的小伙伴每次写组件都会习惯性在constructor和super中写上props,那么这个是必要的吗?? 首先要明确很重要的一点就是: 可以不写constructor,一旦写了constructor ...

  3. React(六)Props属性

    state 和 props 主要的区别在于 props 是不可变的,而 state 可以根据与用户交互来改变.这就是为什么有些容器组件需要定义 state 来更新和修改数据. 而子组件只能通过 pro ...

  4. react 中state与props

    react 中state与props 1.state与props props是只读属性,只有在组件被实例化的时候可以赋值,之后的任何时候都无法改变该值.如果试图修改该值时,控制台会报错 only re ...

  5. react --- React中state和props分别是什么?

    props React的核心思想就是组件化思想,页面会被切分成一些独立的.可复用的组件. 组件从概念上看就是一个函数,可以接受一个参数作为输入值,这个参数就是props,所以可以把props理解为从外 ...

  6. React中state和props分别是什么?

    整理一下React中关于state和props的知识点. 在任何应用中,数据都是必不可少的.我们需要直接的改变页面上一块的区域来使得视图的刷新,或者间接地改变其他地方的数据.React的数据是自顶向下 ...

  7. React 三大属性state,props,refs以及组件嵌套的应用

    React 三大属性state,props,refs以及组件嵌套的应用 该项目实现了一个简单的表单输入添加列表的内容 代码如下 <!DOCTYPE html> <html> & ...

  8. 【JAVASCRIPT】React学习-巧用 props 的 children 属性实现内容填充

    背景 平常写组件,经常遇到需要获取内容放入组件内部的情形. 实现方法 我们有两种实现方式 1. 自定义 props render 的时候通过获取 this.props.content 填充到组件内部 ...

  9. 巩固java(四)----super和super()

    引言: 一个公司里有普通员工和经理,他们之间有很多共同点,但也有一些差异,比如薪水问题,普通员工只有普通工资,经理在完成绩效后有一定比例的奖金.这时我们可以定义两个类Employee和Manager, ...

随机推荐

  1. json_encode 的局限 , 使用自定义的函数 .returnJson.

    $arr = array("liming", "tom", "green"); $arr2 = array( 1 => "l ...

  2. Groovy学习笔记-实现接口

    1.单个委托方法的实现 button.addActionListener( { println 'Implement ActionListener' } as ActionListener ) 2.实 ...

  3. 关闭Azure虚拟机

    Press the Windows key, and then in the Start page, located at the bottom-left, click the Power butto ...

  4. AVL Tree Deletion

    Overview 知识点: 1. delete函数的signature public AVLTreeNode Delete(AVLTreeNode node, int key) 2. 算法,如何删除节 ...

  5. Kylin引入Spark引擎

    1 引入Spark引擎 Kylin v2开始引入了Spark引擎,可以在构建Cube步骤中替换MapReduce. 关于配置spark引擎的文档,下面给出官方链接以便查阅:http://kylin.a ...

  6. Java实现inputstream流的复制

    获取到一个inputstream后,可能要多次利用它进行read的操作.由于流读过一次就不能再读了,而InputStream对象本身不能复制,而且它也没有实现Cloneable接口,所以得想点办法. ...

  7. 使用command line测试网速

    wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py --no ...

  8. webpack 学习之旅

    首先理解wepack的打包原理:一般单页面应用,你的页面都会引入一个类似bundle.js的文件,在react项目中,你会发现index.html中并没有引入css,那么css哪里去了?答案是它被打包 ...

  9. 前端代理----whistle

    场景一:如何将本地的请求代理到服务器上(如果接口没有校验登陆的情况) 最简单的方法:在项目文件中找到webpack开发环境的配置文件,配置devServer对象 devServer: { conten ...

  10. C语言-第2次作业得分

    作业链接:https://edu.cnblogs.com/campus/hljkj/CS20180的2/homework/2292 作业链接:https://edu.cnblogs.com/campu ...