I'm creating objects with private/public access restrictions as commonly promoted by Crockford. For example, I have something like this:
var foo = (function() {
var myPrivateVariable = "whatever";
return {
myPublicFunction:function(str){
return str;
}
}
}());
If I issue a call, such as
myPublicFunction();
Closure should tell me that I'm invoking a function with the wrong number of arguments. I've tried helping Closure out with JavaDoc comments on myPublicFunction:
var foo = (function() {
var myPrivateVariable = "whatever";
return {
/**
* @param {string} str
*/
myPublicFunction:function(str){
return str;
}
}
}());
foo.myPublicFunction();
Still, no complaint. I've tried various forms of JavaDocs for foo, and the only one that worked was to document it as a record type:
/**
* @type {{myPublicFunction:funtion(string):string}}
*/
var foo = (function() {
var myPrivateVariable = "whatever";
return {
/**
* @param {string} str
*/
myPublicFunction:function(str){
return str;
}
}
}());
foo.myPublicFunction();
That worked, but the compiler didn't try to enforce that the myPublic object function actually matched the signature I documented in the record field for the JavaDoc. So this will work so long as I make sure to doc all my functions in these returned objects and make sure I keep the signatures in my docs aligned with what I actually return. Am I missing some better way to enforce this?
Thanks!