What flavor of javascript is cloud code? Some normal JS stuff doesn't seem to work.
J
Jason McIntosh
started a topic
over 6 years ago
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
C
Customer Support
said
over 6 years ago
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?
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
J
Jason McIntosh
said
over 6 years ago
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!
Customer Support
said
over 6 years ago
Glad to hear your worked it out on your own end :)
-Pádraig
D
Dylan Hunt
said
over 5 years ago
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}`;
D
Dylan Hunt
said
over 5 years ago
Update: Does not work, doh :(
s
simon belingar
said
almost 4 years ago
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
S
Sida Li
said
almost 4 years ago
Yes, it is called requireOnce("shortCode");
1 person likes this
D
Dylan Hunt
said
almost 4 years ago
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
D
Dylan Hunt
said
almost 4 years ago
^ I branched this off since I realized it was not related to OP:
Jason McIntosh
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:
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.
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Jason McIntosh
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!
Customer Support
Glad to hear your worked it out on your own end :)
-Pádraig
Dylan Hunt
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}`;
Dylan Hunt
Update: Does not work, doh :(
simon belingar
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
Sida Li
Yes, it is called requireOnce("shortCode");
1 person likes this
Dylan Hunt
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
Dylan Hunt
^ I branched this off since I realized it was not related to OP:
https://support.gamesparks.net/support/discussions/topics/1000092242
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics