-
Notifications
You must be signed in to change notification settings - Fork 3
implicit_this_proposal
Matěj Štágl edited this page Apr 5, 2022
·
2 revisions
To align with JS/C#, an implicit this
parameter should be provided to function calls. Later we can expand on this and provide this
also in scopes.
Behaviour of implicit this
should mimic JS where possible.
Account = {
balance: 100,
withdraw: (howMuch) => {
this.balance -= howMuch
return this.balance;
}
}
print(Account.withdraw(40)) // prints 60
Currently, we would need to either pass a reference to Account
explicitely as a param or use Account::withdraw
& declare function withdraw
via :
notation.
It is for a consideration whether to implement this via prepending this
in existing BuildArgumentList
or to use a different mechanism.
Regardless of that, explicit params called this
should be illegal and we should throw at compiletime when we encounter such a param.
function myFn(this) { // <-- throws "a parameter at position X can't be named "this")
}