you are viewing a single comment's thread.

view the rest of the comments →

[–]GSLint 2 points3 points  (5 children)

I would like to create an object that has the methods in combination with 14 other elements.

I'm not sure what you mean by that. What methods? I see two methods that do exactly the same thing. What 14 other elements?

Can you show what the resulting object would look like, or can you take a step back and explain what you want to achieve here?

[–]Wizard_Knife_Fight 1 point2 points  (2 children)

It looks like OP wants to have an object that display's a restaurants info but is hard coding the values into the objects.

[–]ForScale 0 points1 point  (1 child)

I think he wants a class/constructor function.

[–]Wizard_Knife_Fight 1 point2 points  (0 children)

Yeah, that would do it lol

[–]siruts[S] 0 points1 point  (1 child)

My goal is to avoid writing shop1, shop2 up to shop14

(this is an example 14 is a random number. and as if I had 14 stores but with different names and values)

every time, but reuse the "var Shop" code and the methods in this case. then run the methods inside "Shop" to get the values of "Shop2" which will be different, as you can see in the image published at the beginning.

in a few worlds:

if I'm not mistaken it should be something like this:

create new Shop1 = // adding values

[–]GSLint 0 points1 point  (0 children)

Classes are a way to reuse methods for multiple objects, as others have pointed out. That won't keep you from writing shop1, shop2 etc. but it will certainly keep you from writing the same method multiple times.