Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 为什么在构造函数中调用super()会返回void_Typescript - Fatal编程技术网

Typescript 为什么在构造函数中调用super()会返回void

Typescript 为什么在构造函数中调用super()会返回void,typescript,Typescript,调用构造函数中的super()会返回void而不是同一类的类型,这有什么特别的原因吗 资料来源: 示例:为什么要这样 它不是更容易阅读吗 var me = super(config); me.config.text = '....'; // <=== Property 'config' does not exist on type 'void'. super(config); config.text = '....'; // <=== Easier? var me=super(配

调用构造函数中的super()会返回
void
而不是同一类的类型,这有什么特别的原因吗

资料来源:


示例:

为什么要这样

它不是更容易阅读吗

var me = super(config);
me.config.text = '....'; // <=== Property 'config' does not exist on type 'void'.

super(config);
config.text = '....'; // <=== Easier?
var me=super(配置);

me.config.text='…';// 你为什么要这样

它不是更容易阅读吗

var me = super(config);
me.config.text = '....'; // <=== Property 'config' does not exist on type 'void'.

super(config);
config.text = '....'; // <=== Easier?
var me=super(配置);

me.config.text='…';// 我找不到文档,但是如果
super
调用返回不同的
this
,那么在调用的其余部分,这个新值将变为
this
。这是ES 2015规范规定的行为。如果查看生成的代码,您将看到
super
的返回值在构造函数的其余部分用作
this

function RoundButton(config) {
    // _this will either be the current this or whatever is returned by _super.call
    var _this = _super.call(this, config) || this;
    // refercens to this are replaces with _this
    _this.config.text = '....'; // <=== Property 'config' does not exist on type 'void'.
    return _this;
}
功能按钮(配置){
//这将是当前this或super.call返回的任何内容
var _this=_super.call(this,config)| this;
//引用此文件将替换为_this

_this.config.text='..';//我找不到文档,但是如果
super
调用返回不同的
this
,那么这个新值将在调用的其余部分变为
this
。这是ES 2015规范规定的行为。如果查看生成的代码,您将看到
super
的值在构造函数的其余部分中用作

function RoundButton(config) {
    // _this will either be the current this or whatever is returned by _super.call
    var _this = _super.call(this, config) || this;
    // refercens to this are replaces with _this
    _this.config.text = '....'; // <=== Property 'config' does not exist on type 'void'.
    return _this;
}
功能按钮(配置){
//这将是当前this或super.call返回的任何内容
var _this=_super.call(this,config)| this;
//引用此文件将替换为_this

_this.config.text='..';//如果它返回了什么,那么它必须是
this
。但是有什么意义呢,因为
this
已经在子类构造函数中可用,您可以从中调用super()。为什么您希望它返回除void之外的任何内容?无论如何,它只会是一个部分初始化的类实例,因此尚未生效。重要的是,也是唯一必要的是,
new
在调用所有构造函数后返回实例。如果它返回了一些内容,则必须是
this
。但是在这一点上,因为
这个
已经在子类构造函数中可用,您可以从中调用super()。为什么您希望它返回除void以外的任何内容?无论如何,它只会是一个部分初始化的类实例,因此还无效。重要的是,也是唯一必要的是,
new
在调用所有构造函数后返回实例。