Form validation can help to reduce the amount of bad data that gets saved to your database. In this article, find out how you can write a simple JavaScript form validator for basic client-side validation, and learn a little bit about JavaScript OOP in the process as well.
The object Band now has two properties, "name" and "genre." With this, it is possible to create an instance of the object Band, and pass it two parameters ("n" and "g"), which are then stored as object properties. Note my use of the "this" keyword, which provides a convenient way to access variables (and functions) which are "local" to the object.
Just as you can define object properties, it's also possible to define object methods - essentially, simple JavaScript functions. A little more evolution, and the Band object now sports a whoRules() method, which uses the value stored in the object property "name."
A couple of interesting things here: first, the object method whoRules() is actually defined outside the object constructor block, though it references object properties using the "this" keyword. Second, just as object properties are defined using "this," object methods need to be defined in the same manner. Witness my addition of…