/*** mySampleFunction does something** @param {json} options Can include 3 fields:* {String} name Some name* {Integer} age Age of a person or something* {String} likes 'Icecream' or 'Pizza'*/function mySampleFunction(options) {options = options || {};//...}But I think *that*s probably not the way to go.Any help would be appreciatedThanks,Lukas
--
You received this message because you are subscribed to the Google Groups "JsDoc Toolkit Users" group.
To post to this group, send email to jsd...@googlegroups.com.
To unsubscribe from this group, send email to jsdoc-2+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jsdoc-2?hl=en.
But what if they don’t like ice cream or pizza? (snort!)
Seriously – should the type be {json} or {Object}? It’s a static object, not a string. I struggle with this question regularly in our libraries. Static objects aren’t classes, just objects and there really isn’t an effective documentary construct for them that I can see. Am I missing something? I end up calling them classes using @class, and there is a sense in which they are…
That looks more like the C typedef which acts like a synonym. Would you consider what is coming in V3 to be appropriate for the following:
Assume I have some class that accepts options as a parameter that are driven by defaults.
MyThing = function(options){…} ;
The options can be overridden at call time: var o = new MyThing({likes: ‘iceCream’, foo: ‘bar’});
But I also allow the user to override the options globally by declaring
MyThing.Defaults = {
likes: ‘pizza’,
foo: null
};
So that at startup or initialization the user can just
MyThing.Defaults.likes = ‘cookies’ ;
Would it look like this?
/**
Does something
@class MyThing
@param {MyThing.Defaults} options The options…
*/
MyThing = function(options){
var runtimeOptions = $.extend({},MyThing.Defaults, options) ;
} ;
/**
The defaults for MyThing
@typedef {MyThing.Defaults}
*/
MyThing.Defaults = {
/**
@type {String}
*/
likes: ‘pizza’,
/**
@type {Number}
*/
foo: null
};
@typedef does not imply @static, right?
Thinking out loud:
“non-static typedef would then be a @class right”
Yes, but, that is not what the google compiler seems to imply. That looks more like a pre-compiler directive – but I think I am reading that implementation too closely. I’m not sure the google compiler semantics are very different from #typedef. Based on what you have said regarding jsdoc, I think, though, you are right, if it is not static, I would need to use the “new” keyword to instantiate it, so it would be a class.
“a static @typedef could just be a @namespace.”
I disagree with that statement. Or, I should say that it is true only syntactically. The implied semantics of the namespace is that it is just container for classes or class-like things, whereas the construct we are talking about is more than just a container – or if you want to insist that it is a container, then you must accept that it contains things other than [just] classes.
The problem, of course, is that we are continuing to use functional (i.e., typedef) and OO (i.e., namespace, classes, even static) lexicon for JS which is neither of those things and both of those things simultaneously.
I also think it is a mistake to think of these things under discussion as just parameters. They could exist anywhere at any time and be consumed by any other valid JS construct. For instance, in our library, we define namespaces for our classes to get them out of the global space and prevent collisions. But there are some runtime objects as well, and we mount them all in a single global variable, somewhat like jQuery’s $. At system startup, the structure of our variable (called “athena”) is well known and documentable. It is not a parameter. It contains only runtime instances of composite and atomic values.
The question is: what is that? It’s not a class, certainly not semantically. Even syntactically, you don’t instantiate it with a “new” keyword. There is a sense in which it feels like a struct, but it’s not. And I can add to it at any time. For instance, if the core loads as:
athena = {
services: new something,
content: new otherthing,
language: “en-US”
}
Then later, if I load module X, it may supplement athena to add athena.X = foobar.
So, here’s what we can say about it. It is static – in the sense that you don’t need to use a “new” keyword to use it. It is a composite structure in that it can hold any other type instance. It is scoped by its parent. It’s like a bag or bucket (or heaven help us, a firkin – yes, I have thesaurus.com open). But those terms carry baggage as well (pun intended).
“bag” or “container” probably come closest to the its actual use, since it is generally used as a convenience to reduce clutter and simplify signatures. If you consider it a pattern, then you would also have to consider a verb to allow for runtime supplementation – i.e., adding things to it at runtime.
Or it could just be a typedef. J