-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Adding ability for deep object property lookup (_.get) #2370
Labels
Comments
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Mar 30, 2016
Inspired by underscore-contrib's `_.getPath` and lodash's deep property access, this adds deep property access array shorthand it many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. It also exposes a convenience function `_.get` for accessing deep properties with a default. Possible Concerns ----------------- While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. Further work ------------ The following methods should probably also accept the array syntax: * `_.result` * `_.has` The following companion methods should be created: * `_.set` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Mar 30, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. It also exposes a convenience function `_.get` for accessing deep properties with a default. Possible Concerns ----------------- While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. Further work ------------ The following methods should probably also accept the array syntax: * `_.result` * `_.has` The following companion methods should be created: * `_.set` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Apr 7, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. * `_.has` * `_.result` (including deep evaluation) Possible Concerns ================= `_.property` ------------ While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. `_.has` ------- This adds some complexity to `_.has` which underpins many methods. It's possible that we may want to use a simpler "flat" version of `_.has` internally. Further work ============ We may want to expose some additional helper methods: * `_.get` * `_.set` * `_.unset` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Oct 1, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. * `_.has` * `_.result` (including deep evaluation) Possible Concerns ================= `_.property` ------------ While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. `_.has` ------- This adds some complexity to `_.has` which underpins many methods. It's possible that we may want to use a simpler "flat" version of `_.has` internally. Further work ============ We may want to expose some additional helper methods: * `_.get` * `_.set` * `_.unset` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Oct 2, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. * `_.has` * `_.result` (including deep evaluation) Possible Concerns ================= `_.property` ------------ While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. `_.has` ------- This adds some complexity to `_.has` which underpins many methods. It's possible that we may want to use a simpler "flat" version of `_.has` internally. Further work ============ We may want to expose some additional helper methods: * `_.get` * `_.set` * `_.unset` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Oct 8, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. * `_.has` * `_.result` (including deep evaluation) Possible Concerns ================= `_.property` ------------ While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. `_.has` ------- This adds some complexity to `_.has` which underpins many methods. It's possible that we may want to use a simpler "flat" version of `_.has` internally. Further work ============ We may want to expose some additional helper methods: * `_.get` * `_.set` * `_.unset` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
captbaritone
added a commit
to captbaritone/underscore
that referenced
this issue
Oct 8, 2016
Inspired by underscore-contrib`'s _.getPath` and lodash's deep property access, this adds an Array deep property access shorthand to many aspects of Underscore, including: * `_.property` * `_.iteratee` and all methods that depend on it. * `_.has` * `_.result` (including deep evaluation) Possible Concerns ================= `_.property` ------------ While `_.property` does not get called in any place that would present a performance concern, `getLength` (which is created by `_.property`) gets used in many places which _may_ have performance ramifications. I've placed the `isArray` call in the outer function of `_.property` in an attempt to reduce complexity inside the generated function. This required defining `isArray` earlier. It's possible that this still isn't fast enough, and we should just define `getLength` manually. `_.has` ------- This adds some complexity to `_.has` which underpins many methods. It's possible that we may want to use a simpler "flat" version of `_.has` internally. Further work ============ We may want to expose some additional helper methods: * `_.get` * `_.set` * `_.unset` Fixes: jashkenas#2372, an elegant solution to an oft requested feature: (see: jashkenas#2370, jashkenas#2268, jashkenas#1169, jashkenas#1266)
use underscore.get module
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is simular to that of lodash and I believe there is a big use for this functionality to be added to the core. One of the biggest benefits of this is that you no longer have to check for undefined up the object chain like so
Before
this.object && this.object.one && this.object.one.two
Now
_.get(this.object, 'one.two')
I found most of this on another post I cannot remember who did it but this is very useful
The text was updated successfully, but these errors were encountered: