Hi there!
I was constantly annoyed by the mjs syntax of importing and some other standard for JS things, but in mJS they are implemented so strange that I have to create a little polyfill to work around.
So, if any of you want to use mJS like a normal people I suggest to try my way)
The result init.js for blink demo with some logs looks like this:
As you see, you can use usual setInterval and require like NodeJS and you could feel free to choose any module’s local name as you want, but first you have to load (why load? why not include like C or just import? ) polyfill to enable new fuctions.
For internal libraries usage you have to convert module in standard way like this:
Or just clone lib content or add your own library with correct module.exports
And this is the polyfill source code:
let module = {exports: null};
function require(path) {
// noinspection JSUnresolvedFunction
load(path);
// console.log('Load path:', path, JSON.stringify(module.exports));
return module.exports;
}
let console = {log: print};
// noinspection JSUnresolvedFunction
load('api_timer.js');
function setInterval(fn, timeout) {
return Timer.set(timeout, Timer.REPEAT, fn, null);
}
function setTimeout(fn, timeout) {
return Timer.set(timeout, 0, fn, null);
}
function clearTimeout(id) {
return Timer.del(id);
}
function clearInterval(id) {
return clearTimeout(id);
}