espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.75k stars 739 forks source link

Update this reference in call/apply/bind types #2334

Closed bobrippling closed 1 year ago

bobrippling commented 1 year ago

this as the first argument means the function is callable as in obj.func(), and that we've specified the type of obj, rather than the type of the first argument.

We can rename this to thisArg to avoid this behaviour, meaning we now have a "real" first argument, that will be the this passed to the function we've specified.

This change also restricts apply's second argument to be an array-like object.

gfwilliams commented 1 year ago

We can do this, but can you not just change the script that makes the typescript decls to just convert this->thisArg if it finds it?

Because I'd imagine we'll find that maybe more functions get added using this as a name later on - and there is no real reason not to use it other than the typescript decls?

bobrippling commented 1 year ago

Nice idea, and yes, that's far more future proof. I've made that change, in both the type-generation code and the docs, so the argument name and its documentation match up still

gfwilliams commented 1 year ago

Looks great - thank you!