Problem understanding .obj vs ["obj"]

For developers using the Construct 2 Javascript SDK

Post » Tue May 10, 2016 6:27 am

Hi

I thought i understanded the difference on .obj and ["obj"], but apparently i don't fully understand.

If you look at the screenshot. I can easily check on:
Code: Select all
self.response.status == "success"

That works without problems.
But i can't do:
Code: Select all
self.errors = self.response.errors

Even if it does exist. So if i use:
Code: Select all
self.errors = self.response["errors"]

It works..

Image

Can anyone explain this behavior ?

EDIT 1:
Code: Select all
self.data = self.response.data

This line is working too, for some reason.

EDIT 2:
I found out that i had to do like this to get it to totally work:
Code: Select all
self["errors"] = self.response["errors"]


-Acey
ImageImage
B
19
S
10
G
2
Posts: 51
Reputation: 2,070

Post » Wed May 11, 2016 10:50 am

In terms of the Javascript language, object.property and object["property"] are identical.

In terms of the minifier, when exporting with "minify script" enabled, object.property will be renamed to something shorter by the minifier, e.g. object.q. However object["property"] will not be renamed. So you should use object["property"] syntax for anything that should not be renamed by the minifier.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest