Waypoint: Make Object Properties Private - Instruction Clarity
See original GitHub issueI have addressed a number of questions regarding this Waypoint over that past week. While I don’t believe the wording of the instructions is to blame for all the confusion, perhaps some clarity could be added at the end to help users understand what needs to be done while also reinforcing the terminology. Additions in bold, deleted text struck through.
Properties Private
Objects have their own attributes, called properties, and their own functions, called methods.
In the previous challenge, we used the this keyword to reference public properties and public methods of the current object.
We can also create private properties and private methods, which aren’t accessible from outside the object.
To do this, just declare properties or functions within the constructor without the
this
keyword.
Let’s create an object with two functions. One attached as a property and one not.
See if you can keep myBike.speed and myBike.addUnit private, while making myBike.getSpeed publicly accessible.See if you can modify the Bike constructor so that both the speed property and the addUnit method are private, while also making the getSpeed method publicly accessible for all objects created from the Bike constructor. We’ll check your work by testing the myBike object we’ve created from the Bike constructor at the bottom of the code.
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (2 by maintainers)
Top GitHub Comments
after countless attemps i got this to pass:
can someone please explain why / what happened??
The instructions for this exercise were very confusing. I got everything that you got, @saifalizafar except for the gear = set. I was trying to do something similar to get getGear to be equal to setGear, but no go. Will try this now.