mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Optimize LoopStatus variable for v8 using class
This commit is contained in:
parent
73b9268e0c
commit
fe0d1a749c
@ -107,6 +107,13 @@ function resolveRenderer(handler) {
|
||||
return createDeferredRenderer(handler);
|
||||
}
|
||||
|
||||
function LoopStatus(getLength, isLast, isFirst, getIndex) {
|
||||
this.getLength = getLength;
|
||||
this.isLast = isLast;
|
||||
this.isFirst = isFirst;
|
||||
this.getIndex = getIndex;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Internal helper method to prevent null/undefined from being written out
|
||||
@ -129,25 +136,26 @@ module.exports = {
|
||||
}
|
||||
var i = 0;
|
||||
var len = array.length;
|
||||
var loopStatus = {
|
||||
getLength: function () {
|
||||
var loopStatus = new LoopStatus(
|
||||
function getLength() {
|
||||
return len;
|
||||
},
|
||||
isLast: function () {
|
||||
function isLast() {
|
||||
return i === len - 1;
|
||||
},
|
||||
isFirst: function () {
|
||||
function isFirst() {
|
||||
return i === 0;
|
||||
},
|
||||
getIndex: function () {
|
||||
function getIndex() {
|
||||
return i;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
for (; i < len; i++) {
|
||||
var o = array[i];
|
||||
callback(o, loopStatus);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal helper method to handle loops without a status variable
|
||||
* @private
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user