bind更改函數的this並返回新函數, 能夠傳參app
call和apply都是改變上下文中的this並當即執行這個函數函數
var test = (() => { const funcTest = (...args) => { console.log('funcTest', [...args]) } // apply 當即執行 const test2 = (...args) => { console.log('test2', ...args) funcTest.apply(null, ['inner', ...args]) } // 使用bind生成新函數 return { test2, src: test2.bind(null, 'config.dir_src'), dist: test2.bind(null, 'config.dir_dist'), test: test2.bind(null, 'config.dir_test') } })()