DEV Community

Discussion on: Write More Robust JavaScript: 7 Best Practices

Collapse
 
brunomguimaraes profile image
Bruno Guimarães

Great article, just one thing. Isn't the first snippet supposed to be addChild(name) ?

Collapse
 
jsmanifest profile image
jsmanifest • Edited

Thank you! The intention of addChild's frog argument was that if the frog were to have children then it should have be instantiated with createFrog right before being passed in the instance. So there's the parent frog who had a baby (and the baby frog should have been instantiated with createFrog which is now also an instance of a frog sometime in our app before being passed as a child)

So in the code it would look something like this:

const mikeTheFrog = createFrog('mike')
mikeTheFrog.addChild(createFrog('william'))
Enter fullscreen mode Exit fullscreen mode

or

const mikeTheFrog = createFrog('mike')
const williamTheChildFrogOfMike = createFrog('william')
mikeTheFrog.addChild(williamTheChildFrogOfMike)
Enter fullscreen mode Exit fullscreen mode