Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Not able to wrap the callback using mJS engine


I am trying to write a simple js that wraps the callback with another function. For example:

function my_callback() {

function wrapper(callback) {
  return function() {
    print("b4 helloWorld");
    callback();   // getting error on this line
    print("8fer helloWorld");

Timer.set(1000, true, wrapper(my_callback), null);

However, I am getting error saying the callback cannot be found in the wrapper function. Is this a bug or limitation of the mJS engine? Any pointer is appreciated. Thanks!


  • My understanding is it should be as follows

    let my_callback = function(){

    and in your timer you have

    Timer.set(1000, true, my_callback, null);

  • SergeySergey Dublin, Ireland
    edited August 2017

    See mjs limitations at

    You cannot return a function. Nested scoping is OK, but closures are not implemented.

    This works:

    Timer.set(1000, true, function() { print(; }, null);
Sign In or Register to comment.