This project is read-only.

Chaining set accessors

Topics: Language Specification
Dec 5, 2013 at 10:43 AM
Chapter 4.5 Object Literals describes get/set accessors. It states that a set accessor must not return anything (must have a void return type). This will disallow writing fluent APIs for chaining.

Is there any specific reason for this limitation? I'd love to see the ability to allow chaining of set accessors.
Dec 5, 2013 at 9:18 PM
This is a limitation of the JavaScript runtime:
var x = { set n() { return 4 } };
var y;
y = x = 3; // y is 3, not 4
Out of curiosity, how would you even use this feature if it did exist?
Marked as answer by Airblader on 12/5/2013 at 1:48 PM
Dec 5, 2013 at 9:34 PM
Edited Dec 5, 2013 at 9:45 PM
Hi Ryan,

thanks for your answer. I actually gotta admit that I got some things mixed up here. You're right, this doesn't really make sense. I apologize!

Just got into Typescript and digging through the spec, so I guess some things still have to settle in. I really love it, though, thanks for your work!