![]() ![]() All that extra information you have to pass into those functions does seem clunky. Instead, you are always calling all of the functions in the handler and passing in a lot of extra information to those functions so that the functions can determine if they need to do something. Usually in the event handler you would look at the event target and then call the necessary functions based on the target. You are using event delegation to handle the click event, which is perfectly fine, but you are deviating a little from how it usually works. But of course there is always more than one way to do things.Īs for your original issue with the event listeners, yes, now that I see everything I think I understand why you think they are clunky. For example, I think a Book might know how to render itself on a page. Personally, I would be tempted to move a lot more into the Book class. Also, I would use a value for read that can be used as a boolean. A book should know if it has been read or not because it is storing that property, so it should be the final arbiter on its read state. Instead of using class names to determine the read state of a book why not just use the read property on the book? Then you wouldn’t have to pass in those last two parameters. Granted, you can do this without the class syntax but I think if you are going to use OOP principles you might as well use the syntax tooĪlso, I think the toggleRead function could use some work. Being a classically trained OOP guy I would also recommend you use the JS class syntax to define a Book class, as I think this will make your code even cleaner. One thing I would suggest is that you take advantage of JS modules and put the Book code into a separate file.
0 Comments
Leave a Reply. |