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

model.omit('attr') returns POJO? #4152

Closed
nnnoel opened this issue Aug 8, 2017 · 1 comment
Closed

model.omit('attr') returns POJO? #4152

nnnoel opened this issue Aug 8, 2017 · 1 comment
Labels

Comments

@nnnoel
Copy link

nnnoel commented Aug 8, 2017

I think #4024 is a working solution to this, but I'm not entirely sure.

Example:

let model = new Backbone.Model({ foo: 'bar', baz: 'qux' });
model.omit('foo') // returns { baz: 'qux' }

As a proxied underscore method, I can understand the default behavior. It seems like in the context of a backbone model though, it should somehow return the model with the omitted fields by default?

Other than by overriding the method chain, possibly supering or calling another util/_ method to have the intended effect, or by instantiating a new model, I'm not sure what the most ideal solution to this would be and whether or not the entity context should be accounted for by default.

@jashkenas
Copy link
Owner

It's intended to return a plain object copy of the attributes with your desired keys omitted.

If you want to mutate your model by removing a key, and firing all of the related change events, you're looking for model.unset('foo').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants