-
Notifications
You must be signed in to change notification settings - Fork 0
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
Improving Object-Oriented Code #2
Comments
Didn't know Issues was disabled. Turned on now! |
Here's how I'd rewrite Rectangle::display() in order to use less display() {
const { x, y, w, h, hit } = this;
hit? fill(255, 150, 0) : fill(0, 150, 255);
noStroke().rect(x, y, w, h);
} |
I did a bit more research and you are right that it should be Looking at the repository, it looks like that code is in place but the markdown is wrong. I've updated it here: 47d7e4c. |
Unlike Java, C#, etc., which are compiled, JS can't easily determine whether an identifier inside a method w/o any prefix is a member of its own class or simply a local variable/parameter. Or it can even be a closure variable! Transpilable languages like Typescript, CoffeeScript,etc., would be able to do some analysis in order to determine whether an identifier w/o any prefix would be a member of its own class. However, such feature doesn't exist yet for those transpilers. And I have my doubts if they'd be willing to add it. |
Shiffman's This Dot Song: :-P |
The
<script>
sketch from https://GitHub.com/crhallberg/CollisionDetection/blob/p5js/Website/object_oriented_collision.html is correct.But somehow, the displayed code in the site doesn't match the actual running code:
https://CrHallberg.com/CollisionDetection/Website/object_oriented_collision.html
B/c this. is missing in many places. For example, inside method
Rectangle::display()
:Clearly
rect(x, y, w, h);
should berect(this.x, this.y, this.w, this.h);
instead!cc @GoToLoop
The text was updated successfully, but these errors were encountered: