cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 158 forks source link

def.js.Object.$set should return the Object #497

Open WhiteTrashLord opened 6 years ago

WhiteTrashLord commented 6 years ago

Would it be possible to change the return type of the method def.js.Object.$set so it returns the Object itself? Does it currently return the old value?

Code like this would be much shorter :)

.$set("key1", "value1").$set("key2", "value2")...

renaudpawlak commented 6 years ago

I just can't believe we have not thought of it before. Have you tried to change the prototype and see what happens with the generated code? There is a chance it works as is :)

WhiteTrashLord commented 6 years ago

I am using the Eclipse plugin. It's a bit hard for me to change the prototype. I hope you can test it yourself :)

lgrignon commented 6 years ago

@renaudpawlak doesn't it transpile to obj["key1"] = value1? If so, chaining won't work.

renaudpawlak commented 6 years ago

@lgrignon: yep you are right. My bad. It requires a change in the core adapter :)