Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Appending and Removing Elements

Constructor and prototype for new list item?

Hello - would a more favorable way to code a new list item be by creating a constructor with some basic properties (like maybe a title or label), then creating a listItem.prototype to handle all the functions? New coder here, just trying to connect some dots!

2 Answers

Hey Jason Gresalfi,

I'm sure you've heard a similar variation of the following quote: "There are many different ways to skin an apple." Well, just as that saying applies to that most awesome of fruits, so does it apply to coding. There are many different ways to code a program. But, first, are you just trying to create some new list items and then append them to an unordered/ordered list?

Apples are indeed awesome - including the over-priced but very delicious Honey Crisp. And yeah, I'm actually referring to the To-Do list project in Andrew Chalksley's Interactive Web Pages video. He wires up a bunch of functions to make actions and I guess a better way to ask my questions would have been more specific, like why did he choose NOT to use a constructor? My guess is because the to-do item itself isn't very complex so there's no need for an elaborate prototype to add all sort of things to the form. As you say, there are a lot of ways to to things and I guess I'll get a better idea with more experience. Thanks!

Ah, I see. I believe he just wanted to code it like that because prototyping isn't any better or worse than doing it the way he did it. It may be easier to read with a prototype. That would be a good challenge, to remake the program using a prototype. I wish you the best of luck, sir!