2018.3.24李锦浩【连续第165天】
作为JavaScript中的函数,其实质也是一个变量,因此也可以作为值来使用。如下:
FunctioncallsomFunction(someFunction,someArgument){
Return someFunction(someArgument)
}
Function add10(num){
Return num+10;
}
Var result1=callsomeFuntion(add10,10);
Alert(result1);//20
Function getGreeting(name){
Return “Hello,”+name;
}
Var result2=callSomeFunction(getGreeting,”Nicholas”);
Alert(result2);//”Hello,Nicholas”
因此,我们可以为比较函数来进行一下改编:
FunctioncreateComparisonFunction(propertyName){
Return function(object1,object2){
Var value1=object1[propertyName];
Var value2=object2[propertyName];
If(value1<value2){
Return -1;
}else if(value1>value2){
Return1;
}else{
Return 0;
}
};
}
明日任务:继续学习JavaScript