[Wish:] Wish value properties could have the same name as methods even both owned by one object
Posted: 03 Aug 2023, 13:33
Currently, method is method. Method will never overwrite value property/dynamic property.
Below codes will output "value property" as usual, unaffected by any duplicate names of methods:
Code1:
Also currently, dynamic property is property. dynamic property will never overwrite method.
Below codes will output "method" as usual, unaffected by any duplicate names of dynamic properties:
Code2:
But currently, value property will overwrite method with same name, unlike how dynamic property or method behave.
Code3:
In Code2, if you want to clearly overwrite the method f and run, you always can write c2.DefineProp('f',{call:ths=>OutputDebug(2)}).f().
But currently you can also write c2:={base:c,f:ths=>OutputDebug(2)},c2.f().
It doesn't make sense to offer two ways to achieve the same goal in this situation. Method for overwriting method, callable property for temporary use, seem more reasonable. callable property will only get used, only when samename-methods don't exist in c2 and its bases or are deleted.
Why not to unlock it that all kinds of properties could have the same name as methods even in one object? It is backwards compatible to achieve this. It's just purely something of unlock. It has no side-effects to existing codes as well as the existing DefineProp(free to allow call and value/get,set to be together in Desc).
Slow down the performance? when method is not defined in prototype? I surprisingly cannot find any shortages for this wish at this time.
Below codes will output "value property" as usual, unaffected by any duplicate names of methods:
Code1:
Code: Select all
class CCC {
p:="value property"
}
c:=CCC()
c2:={base:c}
c2.DefineProp('p',{call:(ths)=>89})
OutputDebug(c2.p)
Below codes will output "method" as usual, unaffected by any duplicate names of dynamic properties:
Code2:
Code: Select all
class CCC {
f(){
OutputDebug('method')
}
}
c:=CCC()
c2:={base:c}
c2.DefineProp('f',{get:(ths)=>OutputDebug("Property")})
c2.f()
Code3:
Code: Select all
class CCC {
f(){
OutputDebug('method')
}
}
c:=CCC()
c2:={base:c}
c2.DefineProp('f',{value:89}) ;Cannot use c2.f:=xxx currently.
c2.f() ;Method is overwriten by property and throw.
But currently you can also write c2:={base:c,f:ths=>OutputDebug(2)},c2.f().
It doesn't make sense to offer two ways to achieve the same goal in this situation. Method for overwriting method, callable property for temporary use, seem more reasonable. callable property will only get used, only when samename-methods don't exist in c2 and its bases or are deleted.
Why not to unlock it that all kinds of properties could have the same name as methods even in one object? It is backwards compatible to achieve this. It's just purely something of unlock. It has no side-effects to existing codes as well as the existing DefineProp(free to allow call and value/get,set to be together in Desc).
Slow down the performance? when method is not defined in prototype? I surprisingly cannot find any shortages for this wish at this time.