Skip to content

Instantly share code, notes, and snippets.

@adamsilver
Created October 28, 2010 11:09
Show Gist options
  • Save adamsilver/651119 to your computer and use it in GitHub Desktop.
Save adamsilver/651119 to your computer and use it in GitHub Desktop.
var Field = function() {
this.validate = function() {
// ...
}
}
// the form holds many fields but they both have the same named public method "validate"
var FormValidator = function() {
var fields = [];
// ...
// store field instances in above array
// ...
this.validate = function() {
// loop through all instances of a Field
// calling a method on field instance
fields[i].validate();
}
}
// so i can do one or both of the following
new FormValidator().validate();
new Field().validate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment