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. Django中Form验证

    Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 一,Form验证 第一种操作:主要是这三个函数 ...

  2. Linux:OpenSUSE系统的安装

    又过了比较长的时间,基本上都是一周一更了,这期我们就来演示Linux系统中OpenSUSE系统的安装吧! 安装OpenSUSE系统 系统映像文件下载 OpenSUSE 15下载地址: https:// ...

  3. Java垃圾回收机制和注解

  4. webservice和dubbo区别

    webservice  不需要搭建注册中心,是一个服务框架,主要内容有soap协议,uuid注册中心,wsdl文件. dubbo   需要搭建注册中心,可以是zookeeper,redis.它是一个分 ...

  5. spring cloud配置高可用eureka时遇到的一些坑

    考虑到注册中心的高可用,今天搭建一下eureka集群,并在中途遇到一些小的坑,前前后后花了两个小时来排除,在这里记录一下,以供后面查看. 首先,贴上要达到的效果: 一.起两个eureka模拟集群,在D ...

  6. java学习初体验NO.1

    一.学习目标: 1.理解Java编译原理 在Java编程语言中,所以源代码首先以用.Java扩展名结尾的纯文本件编写,然后,编译器将这些源文件编译成.Class文件.然后,Java启动器工具使用Jav ...

  7. leetcode 买卖股票问题

    leetcode121 Best Time to Buy and Sell Stock 说白了找到最大的两组数之差即可 class Solution { public: int maxProfit(v ...

  8. C#控件之ComboBox控件使用

    首先如果要给ComboBox控件输入要显示的内容,方法是点击控件会显示如下图所示: 然后点击”编辑项”,如下所示: 下面在这里输入控件要显示的内容,即可. 如果要让ComboBox控件设置默认显示项, ...

  9. videojs播放直播源rtmp时画面在左上角解决方案

    问题描述:https://stackoverflow.com/questions/30383135/videojs-live-rtmp-stream-player-and-video-size-iss ...

  10. Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfu

    SQL: Cannot create JDBC driver of class '' for connect URL 使用数据库数据源的web 项目,发布后,访问数据库500报错: 浏览器端: 控制台 ...