If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I want to make a cashregister framework in javascript. I'm used to make such things in fully OOP languages like C# and java, and thought it would be a challenge to make the same using javascript. In this example I try to print out the name of the objects in the items array, this array should be a property of the cashRegister object. I expected to see "cola", but i don't get any output. Sorry for my bad English, I'm a Belgian IT student.

This now makes your object semi-completely functional, however, the way you're trying to access the data is flawed.

Code:

for (items in myCash.items) {
document.writeln(items.name);
}

Here, you're setting a variable "items" to be equal to each key of myCash.items. Then, in the next line, you're trying to read an array of the key called "name". Naturally, something like this would be undefined.

Thanks for the help. But I don't really like the javascript way, it really looks old-fashioned. I'm using the OOP-language way, which is in my opinion much better because it makes it more easy to use it as a extern library.

As someone who run around .Net framework since version 2.0, I could say propotype of javascript is something really amazing that .Net framework will never has it even if you use MSIL.

If you like OOP concept, I suggest you study about real concept of OOP, not just their formation. After you understand OOP concept's purpose, you should study about Refactoring. If you can master these thing, your will coding OOP style in almost language like you breath

As someone who run around .Net framework since version 2.0, I could say propotype of javascript is something really amazing that .Net framework will never has it even if you use MSIL.

If you like OOP concept, I suggest you study about real concept of OOP, not just their formation. After you understand OOP concept's purpose, you should study about Refactoring. If you can master these thing, your will coding OOP style in almost language like you breath

Well I don't know if really understand what you mean... I've had OOP course in school, making UML schemes, learning about inheritance, polymorfism, and other related things. You mean to tell me there is more i have to know?

Yes, you need more then that if you want to master of OOP.
Try to question when you coding like "is it necessary to do this ?" or "what is this object really need to ?" and your code will better. As long as you don't understand root concept of OOP, you can't manipulate them as you will, all you can do is just follow other people suggestion.

I recoding some of your code to be an example how OOP should be.
1. Inner value like an array of receipt shouldn't touch by outside, think about someone put other object into your CashRegister.items, I'm sure it will be really ugly.

2. Name of class, method or variant should tell user about what's it do.