Skip to content

Add class method and tests for p5.Vector.toString() #5348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

weslord
Copy link
Contributor

@weslord weslord commented Jul 9, 2021

Addresses #4852

Changes

Add tests for p5.Vector.prototype.toString()
Add class method and tests for p5.Vector.toString()

Notes

Adding class method p5.Vector.toString() for consistency's sake, as per #4852, but noticed that this has the small side effect of overriding the inherited default method from Function.prototype.toString(), which returns the code that defines a function. I think it's unlikely anyone depends on that original behaviour, but since it's a breaking change I figured I'd split this particular change off of the rest of the static/class methods in #5044. This way we can discuss it separately.

One weird ramification is that defining p5.Vector.toString = (v) => v.toString() caused problems with unit tests for instanceof p5.Vector - I haven't dug in to figure out why, but I did find out that p5.Vector.toString = (v) => String(v) seems to work just fine. Strange, right?

PR Checklist

@Qianqianye
Copy link
Contributor

Thanks @weslord! Add the Math area stewards @limzykenneth, @jeffawang, @AdilRabbani to review the PR.

@Qianqianye Qianqianye requested a review from limzykenneth July 15, 2022 17:24
@limzykenneth
Copy link
Member

Because toString is usually a built in function with specific expectation, can the implementation here be made so that it returns what it would have returned originally when no arguments are passed to the static function? (This is also the reason why the .toString() version doesn't work btw)

@Qianqianye
Copy link
Contributor

Hi @weslord, we'd like to follow up with this pull request. Will you be able to respond to @limzykenneth's comments? Please let us know if you need any clarification. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants