Page 1 of 1

[Idea:] Introduce Super(arg) usage for Fat arrow functions

Posted: 16 Jul 2023, 11:20
by V2User
Wish => could support Super(arg).
Code:

Code: Select all

f(ths)=>ths.fc() ; It seems convenient to support f(ths)=>Super(ths).fc() also.
CCC.Prototype.DefineProp('ff',{call:f})
CCC().ff()
Class CC{
	fc(){
		OutputDebug("Super")
	}
}
Class CCC extends CC{
	fc(){
		OutputDebug("this")
	}
}
Currently, => can support 'this' through ths. Maybe it can also support 'Super' usage through Super(ths). Although this time keyword Super acts more similar to a function accepting an extra arg.

Re: [Idea:] Introduce Super(arg) usage for Fat arrow functions  Topic is solved

Posted: 16 Jul 2023, 21:10
by lexikos
What are you expecting it to do?

The whole point of super is that it is relative to the class which contains the method definition, not the runtime class of this. In your example there is no class associated with the function.

this is just a parameter and local variable, implicit for methods. If the function is called as a method, it will be passed this parameter. If a closure is defined inside a method, it can capture the method's this parameter. In that case, maybe super.method() could be made to work like (BaseClass.method)(this), but obviously you can already do the latter. And this doesn't apply to f in your example; that is just an ordinary global function.