58 lines
No EOL
1.1 KiB
HTML
58 lines
No EOL
1.1 KiB
HTML
<h1>Before and After</h1>
|
|
<p><pre class="code">
|
|
// before:
|
|
var exists = array.indexOf(value) > -1;
|
|
// after:
|
|
var exists = Ox.in(array, value);
|
|
|
|
// before:
|
|
var key;
|
|
for (var k in obj) {
|
|
if (obj[k] === value) {
|
|
key = k;
|
|
break;
|
|
}
|
|
}
|
|
// after:
|
|
var key = Ox.keyOf(object, value);
|
|
|
|
|
|
// before:
|
|
var last = arrayWithLongName[arrayWithLongName.length - 1];
|
|
// after:
|
|
var last = Ox.last(arrayWithLongName);
|
|
|
|
// before:
|
|
arrayWithLongName[arrayWithLongName.length - 1] = 0;
|
|
// after:
|
|
Ox.last(arrayWithLongName, 0);
|
|
|
|
// before:
|
|
myString = myString.substr(2, myString.length - 4);
|
|
// or:
|
|
myString = myString.substring(2, myString.length - 2);
|
|
// after:
|
|
myString = Ox.sub(myString, 2, -2);
|
|
|
|
// before:
|
|
myArray = myArray.filter(function(v, i) {
|
|
return i > 1 && i < myArray.length - 2;
|
|
});
|
|
// after:
|
|
myArray = Ox.sub(myArray, 2, -2);
|
|
|
|
// before:
|
|
myNumber = Math.min(Math.max(myNumber, min), max);
|
|
// after:
|
|
myNumber = Ox.limit(myNumber, min, max);
|
|
|
|
// before:
|
|
var random = min + Math.floor(Math.random() * (max - min));
|
|
// after:
|
|
var random = Ox.random(min, max);
|
|
|
|
// before:
|
|
var mod = -1 % 10 // -1;
|
|
// after:
|
|
var mod = Ox.mod(-1, 10) // 9
|
|
</pre><p> |