高阶函数的应用
在原來的函數中加上自己的代碼 擴展原有的方法 //先聲明一個函數
function say (person) {console.log(person +'說情人節快樂')
}
//在函數的內部聲明一個函數,傳遞的參數是一個函數 返回值是一個函數 所以這個是高階函數
Function.prototype.before = function(fn) {
// console.log(this)let that = this;return function() {fn();that(...arguments);}
}
let newFn = say.before(function(){console.log('你 說 hello')
});
newFn('我');
轉載于:https://www.cnblogs.com/guangzhou11/p/11317937.html
總結
- 上一篇: Linux下C语言编程-进程的创建
- 下一篇: SpringBoot原理