Page 1 of 1

javascript version

Posted: Tue Aug 04, 2015 5:55 pm
by Chimrod
Hello,

I'm quite surprised to see comon javascript function not working : Array.filter, Array.forEach, …

What is the java(ecma) script version used in oolite ? The wiki does not specify it.

Re: javascript version

Posted: Tue Aug 04, 2015 8:08 pm
by another_commander
This is what the Debug Console has to say about it on Windows:
Image

Edit to add: Also, at least array.forEach seems to work fine here (quick example randomly picked from the net):
Image

Re: javascript version

Posted: Tue Aug 04, 2015 8:45 pm
by Chimrod
Thanks for your answer, I was getting crazy with this !

I was used to call filter, forEach with this syntax :

Code: Select all

arr.filter(function(item) {
    return …;
});
which seems works fine in a browser, but does not work in oolite.

And inded the filter, forEach require actualy a callback function with arity 3 : element, index, and a reference to the array. This code exemple works :

Code: Select all

    var stations = system.stations.filter( function(el, idx, arr) {
        player.consoleMessage("Found the station " + el.name + "(" + idx + ")");
        return el.allegiance === "neutral" || el.allegiance === "galcop" || el.allegiance === "chaotic";
    });