Last active
May 13, 2022 07:13
-
-
Save abearxiong/ddbe4b0663692860d1138fb2f9afbd11 to your computer and use it in GitHub Desktop.
es6 Array
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
// test Array.from | |
// 第一个参数为来源的值 | |
// 第二个参数为映射转化函数(可选) | |
// 第三个为第二个参数提供this(可选) | |
let helper = { | |
diff: 1, | |
add(value) { | |
return value + this.diff; | |
} | |
} | |
function translate() { | |
return Array.from(arguments, helper.add, helper); | |
} | |
let numbers = translate(1,2,3); | |
console.log('numbers', numbers);// numbers [2,3,4] | |
let helper2 = { | |
diff: 3, | |
} | |
function translate2() { | |
return Array.from(arguments, helper.add, helper2); | |
} | |
let numbers2 = translate2(1,2,3); | |
console.log('numbers', numbers2); // numbers [4,5,6] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment