admin管理员组文章数量:1289634
I am still rather new to building React/Redux apps. I have been building applications and looking at the code of other applications to learn best practice.
Looking over someone's Reducer, many of the case statements looked like so:
case RECEIVE_CURRENT_TEAM:
return _.merge({}, state, {current_team: action.team})
I wanted to know what _. before merge is doing.
The way I would write the above in my reducer is as follows:
case RECEIVE_CURRENT_TEAM:
return merge({}, state, {current_team: action.team})
I wanted to know the benefit if there was any to _. as I am at the very beginning of building out my next app.
I found some info, but it was vague and linked documentation for _ extend in JavaScript, but the link was broken.
Thanks for the help!
I am still rather new to building React/Redux apps. I have been building applications and looking at the code of other applications to learn best practice.
Looking over someone's Reducer, many of the case statements looked like so:
case RECEIVE_CURRENT_TEAM:
return _.merge({}, state, {current_team: action.team})
I wanted to know what _. before merge is doing.
The way I would write the above in my reducer is as follows:
case RECEIVE_CURRENT_TEAM:
return merge({}, state, {current_team: action.team})
I wanted to know the benefit if there was any to _. as I am at the very beginning of building out my next app.
I found some info, but it was vague and linked documentation for _ extend in JavaScript, but the link was broken.
http://documentcloud.github.io/underscore/#extend
Thanks for the help!
Share Improve this question asked Oct 16, 2017 at 1:04 hanchohancho 1,4373 gold badges23 silver badges44 bronze badges 03 Answers
Reset to default 7_
is not a Javascript feature. It is a monly-used library.
It could either be a reference to lodash
or underscore
.
Both libraries have great documentation so you can lookup what each function does.
The other folks have mentioned that _
is usually either lodash or underscore, but you should know there's nothing mystical or magical about these functions/libraries. You can make one too.
var _ = (function() {
function greet() {
console.log("hi there!");
}
return {
greet
}
})()
_.greet();
If you don't want lodash/underscore (which exactly is _
), you may try for example ES7 syntax
Object.assign({}, state, {current_team: action.team})
or
{ ...state, current_team: action.team }
本文标签: reactjsWhat does quotquot (insert function) do in JavaScript (React example)Stack Overflow
版权声明:本文标题:reactjs - What does "_" .(insert function) do in JavaScript? (React example) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741423131a2377921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论