I think I should listen to the guy here who always tells me "post code"!
1st, thanks for the new information. I hadn't previously seen the mechanism
for adding default values through params; that's neat.
The specific scenario I was envisaging looks a bit like this:
exports.name = "demo";
exports.params = [
{"name":"p1"},
{"name":"p2"}
];
exports.run = function(p1, p2) {
console.log(typeof p2);
console.log(p2);
};
Then a tiddler containing:
<<demo "p1 data">>
results in a console log of String and nothing else.
According to my reading on JS, what I should see is undefined undefined.
If I understand you correctly, what you are saying is that TW overrides JS
default behaviour in case someone tries to
return p2;
incorrectly?
On Monday, 13 March 2017 20:33:38 UTC+11, PMario wrote:
>
> On Monday, March 13, 2017 at 10:15:52 AM UTC+1, tejjyid wrote:
>>
>> OK, but I can accidentally return an undefined paramenter any time,
>> surely?
>>
>
> If you define your params like this. eg:
>
> exports.params = [
> {"name":"tag", "default":""},
> {"name":"label", "default":"<$view field='title' format='text' />"},
> {"name":"tooltip", "default":""},
> {"name":"debug"}
> ];
>
> Since params has to exist, there shouldn't be an accidents.
>
>
>> This slightly unexpected behaviour only protects against variables named
>> in the function definition?
>>
>
> kind of. There is no mechanism in js, that tells you about returning
> undefined variables. The developer has to take care for this.
>
>
>> Also, I notice Jeremy says "undefined".
>>
>
> IMO it should show, that undefined is a string. In js undefined is the
> default state, if you define are variable, without initialisation.
>
> undefined is not equal to the string "undefined"
>
> -m
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/714bd4f8-553a-416a-b941-df8b1477b6c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.