<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var arr = [2, 34, 5, 33, 45]
var temp;
arr.prototype = Array.prototype.for;
Array.prototype.for = function () {
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
arr.for();
alert(arr)
</script>
<!-- <script>
function Arr() {}
Arr.prototype.newarr = [2, 1, 8, 56, 24, 45, 32];
Arr.prototype.forSort = function () {
for (var i = 0; i < arr.newarr.length; i++) {
for (var j = i + 1; j < arr.newarr.length; j++) {
if (arr.newarr[i] > arr.newarr[j]) {
var temp = arr.newarr[i];
arr.newarr[i] = arr.newarr[j];
arr.newarr[j] = temp;
}
}
}
document.write(arr.newarr);
};
var arr = new Arr();
arr.forSort();
</script> -->
</body>
</html>
网友评论