writing a simple helper module #1133
Replies: 8 comments
-
Posted at 2018-01-28 by PaddeK Hmm first guess is you need to create an instance of your jstools "class" with new.
Not tested... but should work :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by @MaBecker thanks for your suggestion, this is the output
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by PaddeK Oh i made a mistake.. try to change the require statement to this..
If the module is in the same directory of course. Important point is to provide the path (absolut or relative) to the module. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by @MaBecker Thanks, just got it. just export each function and that's it.
and no more erros :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by PaddeK Exporting each function removes the need to instantiate with new but should not change the mistake i made with the require. Very Strange.. but glad it works now :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by @MaBecker The require('jstools') works because working with the WebIDE and store the jstools.js file in the module directory of my working project. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-28 by PaddeK Ah this explains it.. i develop my modules in a IDE and serve them via a server on localhost. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-01-29 by @gfwilliams There's some info on making modules here: http://www.espruino.com/Writing+Modules It's for the website, but that way of working can go equally well when trying to build a module in. But yes, the main thing is anything you want to access directly should just be One other thing to note: If you're trying to do arrays in a built-in module, try and do them inside a function where possible:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-01-28 by @MaBecker
The plan is to write a module and include it in custom build with JSMODULESOURCES to have all nice tools in place without wasting time on load.
Starting with a time helper as sample, I was fiddling around and have no clue how to write a working module. Any suggestions how to make this work?
Beta Was this translation helpful? Give feedback.
All reactions