Sign In Register

How can we help you today?

Start a new topic
Answered

What flavor of javascript is cloud code? Some normal JS stuff doesn't seem to work.

I'm trying to use the find() method on an array, as described here. But cloud code seems to think that the method doesn't exist for an array object.


My code looks like this: 

var item = list.find( function( other ) { return other.id === itemId } );

 

According to the test harness, "list" is definitely an Array object of the expected type.

   

Did I screw up something? Or are there parts of normal JS missing that we have to "trial and error" to figure out? That is going to be a huge time sink, if there is no comprehensive documentation reference.


Best Answer

Hi Jason,


The Cloud Code uses Rhino JS as its JavaScript engine and so it may not be updated to the latest ECMAScript version. For ease of use I'd recommend ignoring any methods that came after ECMAScript 2015 (Array.prototype functions like map/reduce are also not supported either).


In the meantime, might I suggest using an older method such as indexOf?


-Pádraig


^ I branched this off since I realized it was not related to OP:

https://support.gamesparks.net/support/discussions/topics/1000092242

yep requireOnce() should really the default shown in every single doc/tutorial.


------------------


@Staff: Any ETA on turning on that ES6 const parameter in Rhino? It's super dated and cross-compatible with ES5 -- it may deprecate some ES5, but nothing is actually removed. I found myself the other day on an ES6 project code in ES5 and I was a bit disgusted with myself: It's really unfortunate to continue using ES5 in 2019~ 


You'd have more-optimized coding, less support tickets, and it just makes sense -- it looks really bad on GS that ES5 is the top level when Rhino supports ES6 with a single parameter change. "Amazon BaaS service uses ES5" just .... sounds really unprofessional: Much like an IT security company's website lacking SSL/TTLS (https).


------------------

@Staff: How to enable ES6:


1. You need to call Context.setLanguageVersion to select the ES6 version or select -version 200 on the CLI. 



....that's actually it. Just step 1 :P With the acquisition from Amazon, the past year of hyping us up for something really awesome has not.... exactly been what we dreamed of :P if you guys could just flip this switch, that'd give us all the morale in the world. It's so easy, backwards-compatible, and in 2019 being an Amazon service, wouldn't this just make sense?


4 people like this

Yes, it is called requireOnce("shortCode");


1 person likes this

Just a follow up on this: do we have a "require_once" alternative ? "require" does work, but double includes can happen really fast with multiple modules working together

Update: Does not work, doh :(

Hi guys, apologies for the necro bump, but pretty related :) As of now, are you guys still at ECMA5-ish standard? I am just wanting to make sure I start on the right foot!


Do `backticks`  work? Can I do something like this?


var myName = "Dylan";

var hello = `my name is ${myName}`;

Glad to hear your worked it out on your own end :)


-Pádraig

Hi Pádraig,


After posting, I noticed the method is ES6. *facepalm* :D


The values in the array are not primitive types, so indexOf() wouldn't work because the compare operation isn't based on the element itself. I just used a for loop.

Thanks!


Answer

Hi Jason,


The Cloud Code uses Rhino JS as its JavaScript engine and so it may not be updated to the latest ECMAScript version. For ease of use I'd recommend ignoring any methods that came after ECMAScript 2015 (Array.prototype functions like map/reduce are also not supported either).


In the meantime, might I suggest using an older method such as indexOf?


-Pádraig

Login to post a comment