funcOne(cb) {
//some async actions
cb(resp) //pass resp to callback function
}
fucntionTwo(resp) { console.log(resp) }
fucntionThree(resp) { console.log(resp) }
funcOne(funcTwo)
funcOne(funcThree)
Run Code Online (Sandbox Code Playgroud)
在上述情况下,函数一将运行两次,如何使 funcOne 运行一次但触发 funcTwo 和 funcThree?我需要从 funcOne 传递 resp 并执行funcTwo,funcThree意味着在 funcOne 中传递多个回调。
我知道我可以传递多个参数,但是还有其他方法可以做到这一点吗?
试图使用lodash的反跳来反跳一个输入,但是下面的代码给了我undefined值。
const { debounce } from 'lodash'
class App extends Component {
constructor(){
super()
this.handleSearch = debounce(this.handleSearch, 300)
}
handleSearch = e => console.log(e.target.value)
render() {
return <input onChange={e => this.handleSearch(e)} placeholder="Search" />
}
}
Run Code Online (Sandbox Code Playgroud)