mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Optimized forEachProp when looping over an array
This commit is contained in:
parent
064dcfbac2
commit
e98fff9e1b
@ -146,9 +146,16 @@ module.exports = {
|
||||
if (!o) {
|
||||
return;
|
||||
}
|
||||
for (var k in o) {
|
||||
if (o.hasOwnProperty(k)) {
|
||||
func(k, o[k]);
|
||||
|
||||
if (Array.isArray(o)) {
|
||||
for (var i=0; i<o.length; i++) {
|
||||
func(i, o[i]);
|
||||
}
|
||||
} else {
|
||||
for (var k in o) {
|
||||
if (o.hasOwnProperty(k)) {
|
||||
func(k, o[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
1
test/autotests/render/for-array-index/expected.html
Normal file
1
test/autotests/render/for-array-index/expected.html
Normal file
@ -0,0 +1 @@
|
||||
0) red1) green2) blue
|
||||
3
test/autotests/render/for-array-index/template.marko
Normal file
3
test/autotests/render/for-array-index/template.marko
Normal file
@ -0,0 +1,3 @@
|
||||
<for(i, color in ['red', 'green', 'blue'])>
|
||||
${i}) ${color}
|
||||
</for>
|
||||
1
test/autotests/render/for-array-index/test.js
Normal file
1
test/autotests/render/for-array-index/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user