mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
32 lines
819 B
JavaScript
32 lines
819 B
JavaScript
function LoopStatus(getLength, isLast, isFirst, getIndex) {
|
|
this.getLength = getLength;
|
|
this.isLast = isLast;
|
|
this.isFirst = isFirst;
|
|
this.getIndex = getIndex;
|
|
}
|
|
|
|
module.exports = function forEachPropStatusVar(object, callback) {
|
|
var keys = Object.keys(object);
|
|
|
|
var i = 0;
|
|
var len = keys.length;
|
|
var loopStatus = new LoopStatus(
|
|
function getLength() {
|
|
return len;
|
|
},
|
|
function isLast() {
|
|
return i === len - 1;
|
|
},
|
|
function isFirst() {
|
|
return i === 0;
|
|
},
|
|
function getIndex() {
|
|
return i;
|
|
});
|
|
|
|
for (; i < len; i++) {
|
|
var key = keys[i];
|
|
var value = object[key];
|
|
callback(key, value, loopStatus);
|
|
}
|
|
}; |