SoFunction
Updated on 2025-02-28

js Function type

1. A function is an object, and the function name is a pointer to a function object and will not be bound to a certain function.
2. Functions are not overloaded (function overload: the same function name corresponds to the implementation of multiple functions.)
For Examle:
function addnum(num){return num+10 }
function addnum(num){return num+20}
addnum(10);//30
3. Function expressions and function reputation (the parser will be the first to read the function declaration, and other situations are equivalent).
4. Function as value.
Sort the object array by an object attribute?
Copy the codeThe code is as follows:

function compareFunction(properyName){
return function(obj1,obj2){
var value1 = obj1[propertyName];
var value2 = obj2[propertyName];
if(value1>value2){
return 1;
}else if{value1<value2}{
return -1;
else{
return 0
}
}
}
var data = [{name : "Jin",age : 24},{name:"awei",25}];
(compareFunction("name"));
data[0].name;

5. Internal properties of the function (arguments(callee), this);
6. Properties and methods of functions.
Attributes: length, prototype
Methods: apply(), call()