Last active
May 13, 2019 06:41
-
-
Save viko16/a6e7a284ef082e15c14d1e6392bca04c to your computer and use it in GitHub Desktop.
兼容数组、对象解构的方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 比如 API 暴露 | |
function useApi () { | |
const a = 'a' | |
const b = 'b' | |
const c = 'c' | |
return Object.assign([ a, b, c ], { a, b, c }) // 务必数组在前,否则无法维护下标 | |
} | |
// 使用时既可以 | |
const [ a, b, c ] = useApi() // react hook 风格的数组解构 | |
// 也可以 | |
const { a, b, c } = useApi() // 对象解构 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment