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

oojs/assessment: Shape constructor should take arguments #7

Closed
bergus opened this issue May 4, 2017 · 3 comments
Closed

oojs/assessment: Shape constructor should take arguments #7

bergus opened this issue May 4, 2017 · 3 comments

Comments

@bergus
Copy link

bergus commented May 4, 2017

See http://stackoverflow.com/questions/43785607/inheritance-of-properties-through-passing-constructor-parameters
In general it is a good practise not to perform side effects (random) in constructors, but let the caller who creates the object do this.

@chrisdavidmills
Copy link
Contributor

Argh, dammnit - my brain was out to lunch when I wrote this one ;-|

So, I have updated the call() description in this article:

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance#Defining_a_Teacher()_constructor_function

So that it hopefully makes more sense as to what it is doing.

I have also updated the description of the bouncing balls in the assessment:

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Adding_bouncing_balls_features

And updated the code examples:

https://github.com/mdn/learning-area/blob/master/javascript/oojs/assessment/main.js
https://github.com/mdn/learning-area/blob/master/javascript/oojs/advanced/oojs-class-inheritance-finished.html
https://github.com/mdn/learning-area/blob/master/javascript/oojs/advanced/oojs-class-inheritance-student.html

So I've kinda gone the opposite way here - removing the need for arguments altogether. I still think this is useful to show how a constructor can create an entire object with just a single line of code, even if the attributes are random rather than user defined.

I guess the best practice would be to have the values taken from the parameters rather than being just random, so the caller could decide to create an object of fixed or random size?

@chrisdavidmills
Copy link
Contributor

I've updated the examples and text again, to take the random calls out of the constructor and into the instantiation calls.

@bergus
Copy link
Author

bergus commented May 4, 2017

Thanks for the quick response!
122ba2d fixes the issue.

@bergus bergus closed this as completed May 4, 2017
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