如何将函数名称作为参数传递,而不是将函数调用包含在匿名函数中并将它们作为整体传递。 为什么即使我将函数调用为相同的顺序,两个输出也是不同的。
案例1
class BaseCell: UICollectionViewCell {
override init(frame: CGRect){
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder){
fatalError("init(coder:)has not been implemented")
}
func setupViews(){
backgroundColor = UIColor.white
}
}

案例2
function one(cb) {
console.log("one");
setTimeout(cb, 1000);
}
function two(cb) {
console.log("two");
setTimeout(cb, 1000);
}
function three(){
console.log("three");
}
one(function(){two(three)});

这两行在程序执行方面有何不同
function one(cb) {
console.log("one");
setTimeout(cb, 1000);
}
function two(cb) {
console.log("two");
setTimeout(cb, 1000);
}
function three(){
console.log("three");
}
one(two(three));
答案 0 :(得分:1)
案例1: 你用函数作为参数调用一个。
案例2:
你用一个两(三)作为参数调用一个。这不再是一个功能。
就像function(x){return x*x}(5)
等于25并且不等于函数函数。