[]is just an array literal. This is an empty array because it does not contain any elements. In this context, this is a shortcut to Array.prototype.
This code basically allows you to use the method Array.prototype.sort()even for values that are not arrays, for example arguments.
Further explanation:
[]
.sort
.call(
data,
function (a, b) {}
)
Assuming you have an array-like object, for example:
var obj = {0: "b", 1: "c", 2: "a", length: 3};
, length. .sort() , Object.prototype . Array.prototype.sort() . Function.prototype.call(). .call() - , , - , . :
Array.prototype.sort.call(obj)
, Array.prototype.sort obj.
, Array.prototype , , .
. :