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. 自学python之路(day2)

    1. 格式化输出 %表示占位符 ,s表示字符串 ,d表示数字,%s就是代表字符串占位符,%d,是数字占位符 示例1:输入用户的姓名.性别.年龄.爱好的通用模板 name = input("请 ...

  2. django遇到的问题-系列1

    django开发中遇到的问题以及解决方法: 1.You called this URL via POST, but the URL doesn't end in a slash and you hav ...

  3. js中 setTimeout延时0毫秒的作用

    经常看到setTimeout延时0ms的javascript代码,感到很迷惑,难道延时0ms和不延时不是一个道理吗?后来通过查资料以及实验得出以下两个作用,可能还有作用我还不知道,希望得知的朋友在后面 ...

  4. sys os

     python常用的一些东西——sys.os等(转) 2012-09-19 14:51:4 1.常用内置函数:(不用import就可以直接使用)      help(obj) 在线帮助, obj可是任 ...

  5. python 读取默认配置文件和用户配置文件 configs

    优先从configs_default中读取配置,但是configs_override中的配置可以override它 import configs_default #import configs_ove ...

  6. 【EMV L2】Application Usage Control

    [Application Usage Control] Tag9F07,卡片数据,2bytes: Indicates issuer’s specified restrictions on the ge ...

  7. http协议常见状态码含义

    状态码有三位数字组成,第一个数字定义了响应的类别,且有五种可能取值: 2xx:成功--表示请求已被成功接收.理解.接受 200(成功)  服务器已成功处理了请求.通常,这表示服务器提供了请求的网页. ...

  8. Fedora 系统屏幕亮度修改

    在某些笔记本电脑上,屏幕亮度卡在最大值,功能键或桌面设置似乎没有做任何事情. 有一件事要尝试通常可以解决这个问题.打开/ etc / default / grub 并找到以GRUB_CMDLINE_L ...

  9. 使用new来分配内存

    对指针的工作方式有一定的了解之后,来看看他如何实现在程序运行时分配内存.前面我们都将指针初始化为变量的地址(int * pt; pt = & a):变量是在编译时分配的有名称的内存,而指针只是 ...

  10. vue axios 取消上次请求

    axios.defaults.timeout = 1000 * 5axios.defaults.baseURL = baseUrlvar CancelToken = axios.CancelToken ...