Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object extension literal #2177

Closed
wants to merge 14 commits into from
Closed

Object extension literal #2177

wants to merge 14 commits into from

Conversation

itrelease
Copy link

#2176 and #1632

@michaelficarra
Copy link
Collaborator

So this doesn't appear to actually implement object extension literals, but some .= mutating object extension operator like the one proposed in #880. I'm going to oppose it as an object extension literal, as in #1632, would be a superior language feature. Object extension literals also don't work through mutation, promoting a nice functional style. And no tests?

edit: just read through the object extension literal proposal again, and apparently it does work through mutation :(. That makes me sad. Even more reason to support the Coco style in #1632. No mutation in its semantics.

@itrelease
Copy link
Author

I see the difference only in syntax: .= instead of .{ or I'm wrong? I'll add tests tomorrow.

@michaelficarra
Copy link
Collaborator

No, you're right. It was my mistake. See my edit above.

@TrevorBurnham
Copy link
Collaborator

The branch you're trying to merge appears to have two unrelated changes: The .= syntax, and the attr_reader etc. stuff proposed at #2173. I assume that's unintentional?

Also, no test cases?

@itrelease
Copy link
Author

I removed unrelated changes and added test.

@TrevorBurnham
Copy link
Collaborator

What's with the scope check? Shouldn't a .= {x: 1} be a legitimate way of extending window.a?

@itrelease
Copy link
Author

It will extend variable if it exist in parent scope and throw error if variable wasn't defined.

@TrevorBurnham
Copy link
Collaborator

Hmm, well it is consistent with the new strict error on a ?= b et al.

@michaelficarra
Copy link
Collaborator

@itrelease: @TrevorBurnham is trying to make the point that we should be able to use this operator on externally-defined variables -- things that are in scope, but which CoffeeScript doesn't know about. This can be any property added to the global object (or anywhere up its prototype chain), since the global object is also the root of the scope chain.

edit: @TrevorBurnham: I don't believe it is. Since it doesn't introduce a variable into scope, it should behave more like += (LHS not in scope is allowed).

@itrelease
Copy link
Author

Oh I see, so we should just rely on thing that variable might be in scope and not throwing error?

@itrelease itrelease closed this Apr 11, 2012
@itrelease itrelease reopened this Apr 12, 2012
@vendethiel vendethiel closed this Sep 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants