I am very interested to start using the Prototype library to write OO Code in the hope to eventually switch from my usual procedural style when doing medium to large projects.
I have just read the section on using Classes on the prototype website, and Im impressed with what Ive read. The only thing is Im wondering how would I handle a situation such as ‘invalid’ variables being passed to a constructor?
Say I wrote an app which required a variable with the value of 100 or 200, and failing that condition the program must fall over and inform the user why?
In the initialize method, you’d use an if statement to test if the variable has an appropriate value, and if it doesn’t, then you can throw new Exception(‘with a problem description’)
I find with a lot of projects I write, I can usually get away with only one or two classes, so I tend to use templates like this “basic instantiable object” to get me through the day.
Thanks Jeff that worked a treat. And thankyou Aussie John for your very usefull input, Im going to have a good read through those links.
I have also considered that one or two classes will be enough for most projects, I just noticed that recently my procedural code whilst neat is becoming a little unyealding.
Ive spent the morning writing some test scripts with the Prototype Library and I have to say it works really well!
One thing John, in that ‘Basic Instantiable Object’ example whats with the reference to ‘console’ ? I cannot for the life of me work out what it references.
I have created a working class, and im pleased with the results. But im struggling to work out how to get some inheritance going after having read the other articles.
How would I extend the ‘Animal’ Javascript class in geeky johns article ? an example would be really helpfull Im used to inheritence in Java and I liked how easy it was (similar to Java) with the prototype Library.