require("...") in a js macro ?

46 views
Skip to first unread message

FrD

unread,
Jul 20, 2018, 4:32:07 PM7/20/18
to TiddlyWikiDev
Hi,

I've written two js macros, and part of the code is the same.

So I've put this part in a function (say : myUtilFunction) in another tiddler (say : Utils.js, application/javascript, and module-type : library). At the end : exports.myUtilFunction = myUtilFunction;

Now I'm trying to make this function available int the two macros.
So in the twos macros, before "exports.name = ...", I have :

var myUtilFunction = require("Utils.js").myUtilFunction;

It doesn't work, the error message reads : myUtilFunction is not a function.

I've already used this way in writing a widget and it worked. Is there a pb with macros ?


Any help welcome !

Regards

FrD

FrD

unread,
Jul 21, 2018, 4:31:01 AM7/21/18
to TiddlyWikiDev
Hi,

Sorry, I found a typo in my Utils.js tiddler : I wrote export. ... instead of exports. ...
My bad.

Everything's fine now.

Regards

FrD

PMario

unread,
Jul 21, 2018, 4:46:14 AM7/21/18
to TiddlyWikiDev
On Friday, July 20, 2018 at 10:32:07 PM UTC+2, FrD wrote:

So I've put this part in a function (say : myUtilFunction) in another tiddler (say : Utils.js, application/javascript, and module-type : library). At the end : exports.myUtilFunction = myUtilFunction;

Did you define myUtliFunctin like this?

function myUtilFunction(a, b, c, ..) {
}

-m

FrD

unread,
Jul 21, 2018, 5:05:31 AM7/21/18
to TiddlyWikiDev
Hi PMario,

Most of the time I prefer to define a function this way (in particular for a library) :

var myUtilFunction = function(a,b,c, ..) {
}

Regards

FrD
Reply all
Reply to author
Forward
0 new messages