Hello - a feature suggestion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Hello - a feature suggestion

Benqzq
Please consider adding a `stop` command.

A `stop` command tells a JS interpreter "Go back to the start of the code".

When an event is triggered, he interpreter will run again, until the stop.

This can be useful in this particular case.

--
בשאיפה לעולם שמח יותר לבני אדם וחיות כאחד,

Aspiring for a happier world for humans and animals alike,

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Hello - a feature suggestion

Michael Kriegel

There is no "start of the code" other than the time when the JavaScript is parsed. But as JavaScript can be in multiple places (e.g. included in script tags somewhere in the page) and even be added at run time, it is not clear, what would need to be evaluated again and what not. Also the page may be in a different state from what it was originally in the beginning, so without reloading the page, your code would meet preconditions it did not expect.

From your StackOverflow-question:

"Given the keydown event is triggered only once, I consider sending the interpreter back to the start after the keydown event was triggered disposably, and without refreshing the page (Sorry if it seems absurd, I'm new to JS and failed finding the source of the bug)."

You may use the debugger and set a breakpoint to find your bug.
On 06.09.2017 05:00, Benqzq wrote:
Please consider adding a `stop` command.

A `stop` command tells a JS interpreter "Go back to the start of the code".

When an event is triggered, he interpreter will run again, until the stop.

This can be useful in this particular case.

--
בשאיפה לעולם שמח יותר לבני אדם וחיות כאחד,

Aspiring for a happier world for humans and animals alike,


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

-- 
Michael Kriegel • Head of R&D • Actifsource AG • Haldenstrasse 1 • CH-6340 Baar • www.actifsource.com • +41 56 250 40 02

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Hello - a feature suggestion

kai zhu
i have this problem often and emulate “stop" by wrapping the entire-code inside a function (which is good-practice).  here's my real-world use-case to “stop” depending on browser / nodejs environment

```js
/*
 * example.js
 *
 * this example will stop code-excecution depending on various js-env conditions
 */

/*jslint
    browser: true,
    node: true,
*/

(function () {
    'use strict';
    var local;

    // run shared js-env code
    (function () {
        // init local
        local = {};
        // init modeJs
        local.modeJs = (function () {
            try {
                return typeof navigator.userAgent === 'string' &&
                    typeof document.querySelector('body') === 'object' &&
                    typeof XMLHttpRequest.prototype.open === 'function' &&
                    'browser';
            } catch (errorCaughtBrowser) {
                return module.exports &&
                    typeof process.versions.node === 'string' &&
                    typeof require('http').createServer === 'function' &&
                    'node';
            }
        }());
        console.log('hello world');
    }());
    switch (local.modeJs) {

    // run browser js-env code
    case 'browser':
        console.log(document.querySelector('body'));
        console.log('stop in browser js-env');
        return;

    // run node js-env code
    case 'node':
        // stop if example.js is not invoked from the command-line
        if (module !== require.main) {
            console.log('stop in node non-cli js-env');
            return;
        }
        console.log('hello command-line');
        console.log('stop in node js-env');
        return;
    }
}());
```


On Sep 6, 2017, at 12:20 PM, Michael Kriegel <[hidden email]> wrote:

There is no "start of the code" other than the time when the JavaScript is parsed. But as JavaScript can be in multiple places (e.g. included in script tags somewhere in the page) and even be added at run time, it is not clear, what would need to be evaluated again and what not. Also the page may be in a different state from what it was originally in the beginning, so without reloading the page, your code would meet preconditions it did not expect.

From your StackOverflow-question:

"Given the keydown event is triggered only once, I consider sending the interpreter back to the start after the keydown event was triggered disposably, and without refreshing the page (Sorry if it seems absurd, I'm new to JS and failed finding the source of the bug)."

You may use the debugger and set a breakpoint to find your bug.
On 06.09.2017 05:00, Benqzq wrote:
Please consider adding a `stop` command.

A `stop` command tells a JS interpreter "Go back to the start of the code".

When an event is triggered, he interpreter will run again, until the stop.

This can be useful in this particular case.

--
בשאיפה לעולם שמח יותר לבני אדם וחיות כאחד,

Aspiring for a happier world for humans and animals alike,


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

-- 
Michael Kriegel • Head of R&D • Actifsource AG • Haldenstrasse 1 • CH-6340 Baar • www.actifsource.com • +41 56 250 40 02
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss