下面這只是個例,請問propertyName和object1,object2有什么聯(lián)系?請推廣到一般情況下<script type="text/javascript"> function createComparisonFunction(propertyName) { return function(object1, object2){ var value1 = object1[propertyName]; var value2 = object2[propertyName]; if (value1 < value2){ return -1; } else if (value1 > value2){ return 1; } else { return 0; } }; } var data = [{name: "Zachary", age: 28}, {name: "Nicholas", age: 29}]; data.sort(createComparisonFunction("name")); alert(data[0].name); //Nicholas data.sort(createComparisonFunction("age")); alert(data[0].name); //Zachary </script>
函數的返回值是函數時,這個返回值里面函數的參數和外層函數參數的聯(lián)系?
繁華開滿天機
2018-09-10 14:21:39