Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  172] [ 7]  / answers: 1 / hits: 88631  / 8 Years ago, tue, february 23, 2016, 12:00:00

I have an object that looks like



var foundUser = {
charData: []
}


which then I load an object from a database using mysql and then I call



_.assignIn(foundUser, rows[0]);


But I get a few extra properties that I don't need (this isn't solvable by using select)



So I call



foundUser = _.omit(foundUser, ['blah']);


But it would be nice if I could just do



_.assignIn(foundUser, rows[0]).omit(rows[0], ['blah']);


But that throws an error, am I doing it wrong or is there another way this can be done?


More From » lodash

 Answers
189

To chain with lodash, you first have to wrap the object:



_(foundUser).assignIn(rows[0]).omit(['blah']).value();


Further clarification:



The _ creates a lodash object which allows for implicit method chaining. Implicit method chaining means that in certain circumstances it may return a primitive value, in others it may return a lodash object that you need to unwrap by calling .value() on it.



If you'd use _.chain(...), you'd be creating a lodash object with explicit method chaining. The result is always a wrapped value and always needs to be unwrapped by calling .value() on it.



For further reference here are the links to the documentation:



Explicit chaining in Lodash



Implicit chaining in Lodash


[#63194] Monday, February 22, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossthomasn

Total Points: 122
Total Questions: 78
Total Answers: 105

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
;