Trying to create a "class" in JavaScript that can both have a function at the root of the class and other sub functions:
Validate(word)
- returns true or false if the word is validated
Validate.getRule()
- returns the rules used to validate the word.
Here is example code:
var Validate = function (word)
{
this.rule = /^[a-m]$/;
if (word)
{
return this.rule.test(word);
}
else
{
return {
getRule : function()
{ return this.rule;}
};
}
}();
This works the first time if you call it with no arguments, but the second time I get the following error:
TypeError: object is not a function