Skip to content
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

Jonathan - Fixes #44

Open
soggybag opened this issue Oct 27, 2020 · 1 comment
Open

Jonathan - Fixes #44

soggybag opened this issue Oct 27, 2020 · 1 comment

Comments

@soggybag
Copy link
Owner

function drawRect(x, y, width, height, color) {

Great work. I like your functions. These are a really great idea. You could take this up a notch by including the ctx as a parameter. Without this each of these function assumes there is a variable ctx in scope which may not be guaranteed if you used them in another project.

Fix this by injecting the dependency, which is a fancy way of saying make ctx a parameter.

function drawRect(ctx, x, y, width, height, color) {
  ctx.beginPath()
  ...
}

Here you can get your ctx anywhere and it could have any name:

drawRect(document.querySelector('canvas'), 100, 20, 23, 44, 'red')
@jewarner57
Copy link
Contributor

Resolved.

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

No branches or pull requests

2 participants