JavaScript【高次関数】

4880 ワード

function after(times,callback){
	return function(){	
        if(--times===0){
            callback();
        }
    }
}

let fun = after(3,function(){
	console.log(1)
})
fun(1)
fun(1)
fun(1)  // console.log(1)

//   
function say(who){
	console.log(who+'  ')
}
Function.prototype.before = function(fn){
	let that = this;
	return function(){
		fn();
		that(...arguments);
	}
}
let newFn = say.before(function(){
	console.log('  ')
})
newFn(' ')