oxjs/readme/test2.html

68 lines
1.3 KiB
HTML
Raw Normal View History

2012-03-30 14:17:56 +00:00
<h1>Before and After</h1>
<p><pre class="code">
2012-04-17 12:00:57 +00:00
// before:
for (var i == 0; i < bigArray.length; i++) {
if (bigArray[i].isSelected) {
bigArray[i].onDeselect = (function(i) {
return function() {
doSomething(i);
}
})(i);
}
if (!bigArray[i].isSelectable) {
break;
}
}
// after:
Ox.forEach(bigArray, function(v, i) {
if (v.isSelected) {
v.onDeselect = function() {
doSomething(i);
};
}
return v.isSelectable;
});
2012-03-30 14:17:56 +00:00
// before:
var exists = array.indexOf(value) > -1;
// after:
2012-05-30 16:28:39 +00:00
var exists = Ox.contains(array, value);
2012-03-30 14:17:56 +00:00
// 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:
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
2012-05-30 16:28:39 +00:00
</pre><p>