-
Notifications
You must be signed in to change notification settings - Fork 2
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
Getting the whole assigned result #9
Comments
FYI, I think this use-case can already be handled decently with: let x, { y } = x = { y: 1 }; Unfortunately, with const x = { y: 1 }, { y } = x; |
@getify - I don't think this is what @micnic wanted though. The use case I'm thinking of is something like this:
|
@pldilley the intention as i see it of this proposal is very much not to provide that, but instead to provide the full object as the |
Please can you give me an example? From what I understand, it's this:
Wouldn't make sense for x to include c. That would mean x and test are just the same - something we already have! |
No, It's not that useful for variable destructuring of the top level - it's much more useful for destructured function arguments, and nested destructured arguments. |
Ah I see... Well I have to admit I'm not so sure that's useful... For example: Why not just do (less characters too):
|
Because then, to also create a c binding, you have to do a second destructuring line. |
Apologies for the repeat postings. There's a strawman proposal for what I (and micnic?) was hoping for: https://github.com/rtm/js-pick-notation |
@pldilley actually, when I originally asked this question did not think about the "restructure", I was concerned only about the creation of an object and in the same time to get a reference to it and it's members. Only after you proposed to "restructure" the object I was thinking that it's a good idea, but still, I think we should not go too far from "import as" and "export as" semantics. |
Thank you for your responses to both of you :) I agree with what has been said about |
I would like to see this syntax for precisely the use-case of function arguments: const fn = ({h} as ctx, [first] as arr) => {
// ...
} I posted about this on discourse and got pointed to this proposal: https://es.discourse.group/t/destructure-an-argument-and-retain-a-reference-to-the-original-argument/311/2 I really like this proposal 👍 it's even better and more expansive than I the simple idea I had. wait, upon reading more closely, I want a reference to the original object/array, not to a restructured version of it with only the single parameter I needed out of it. my use case is I often times pass around an object between functions, like a context or language texts which I need to pick only certain ones out of the object, and I want to pass the original object on in it's entirety to the next function. eg. const render_something = ({h} as ctx, ...args) => {
return h('div',
// stuff
render_something_else(ctx)
)
} |
I don't think it makes sense at all for |
Thinking about this further, I could imagine flipping it around to: function renderSomething(ctx as { h }) {
// ..
} In that order, it makes a little more sense to me that Maybe we could instead do: function renderSomething(ctx with { h }) {
// ..
} |
I like both of those ideas my old-school js knowledge tells me to never use the with keyword, ever :) the const orig_obj = { lala: 1234, not_included: 'below' }
const obj = orig_obj as { lala }
// which is essentially the same as:
const orig_obj = { lala: 1234, not_included: 'below' }
const { lala } = orig_obj
const obj = { lala } which I think is quite cool! great suggestion!! |
As I see the examples for this proposals mainly cover the nested object properties / array elements value accessing, but can it be used for getting the whole value that is assigned?
Is the following behavior valid in the context of this proposal?
The text was updated successfully, but these errors were encountered: