Skip to content
Advertisement

How to create a class that holds collection of other class in JavaScript

I want to create a class called SchoolCatalog that will hold a collection of schools, e.g. Create an instance of SchoolCatalog for primary, middle, and high schools. (This is one of the problems from Code Academy Introduction To JavaScript). But, they have no proper guide on how to make a Catalog to hold all classes in the forum. So, if anybody can help me out I will be grateful.

JavaScript

Advertisement

Answer

Is there an issue with your implementation ?

JavaScript

If I needed a list I could iterate over and still easily get single schools from this is how i would do it ,

That said depending on your requirements this could be totally wrong.

Your implementation at first blush doesn’t look to be incorrect , is it giving you a error?

Advertisement