I have this simple code in blog1.js:
var blog_validation = (function() {
var fields = {}
var email = function() {
console.log("validating email")
}
var add_field = function(field, type) {
fields[field] = type;
}
return {
fields: fields,
email: email,
add_field: add_field
};
})();
and this in blog2.js:
(function() {
blog_validation.add_field("test", "email");
blog_validation.fields['test']();
})();
In the example above i have hard-coded the "test" string for easier troubleshooting instead of writing in a for loop iterating over all the hash values. The email function also doesnt do anything for now, im just going to see if it gets called correctly.
Basically calling the function reference in the hash does not work, it just says that "string is not a function".
From other resources on the net ive seen people save functions in a hash and then call them later like that but i havent seen people storing function references so im not sure if this would work but since you can store functions in a hash i guess you would be able to store a function reference as well ?
Can someone explain why this isnt working ?