关于js函数的,function text(){} 和 text=function(){}的区别

    var arr = [11, 23, 42, 44, 56, 55, 7, 3, 1, 5];
    function sort(arr, compare) {
      if (!compare) {
        compare = function (a, b) {
          return a - b > 0 ? 1 : (a - b < 0 ? -1 : 0)
        }
      }
      for (var i = 1; i < arr.length; i++) {
        for (var j = 0; j < arr.length - i; j++) {
          if (compare(arr[j], arr[j + 1]) > 0) {
            var temp = arr[j];
            arr[j] = arr[j + 1];
            arr[j + 1] = temp;
          }
        }
      }
      console.log(arr)
    }

一个冒泡排序的函数,compare函数是排序条件

假如把compare = function(){} 换成 function compare(){},运行sort函数就会报错“找不到compare函数”,是为什么呢?

text=function(){}是匿名函数,function text(){} 是普通函数。

你在sort里面肯定不能去定义函数了。