New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object iterators added. #67
Conversation
See advancedsnippet.txt
And tests for this: describe("iterate object (for..in)", function() {
function Obj() {
this.awesome = "doT.js";
}
Obj.prototype = {
one: 1,
2: "two",
THREE: 3
};
var obj;
beforeEach(function() {
obj = new Obj();
});
it("should iterate all object properties", function() {
var tpl = doT.compile('{{@ it :val :key}}[{{=key}}={{=val}}]{{@}}');
var exp = '';
for (var k in obj) {
exp += "[" + k + "=" + obj[k] + "]";
}
expect(tpl(obj)).toBe(exp);
});
it("should iterate only own properties", function() {
var tpl = doT.compile('{{@@ it :val :key}}[{{=key}}={{=val}}]{{@@}}');
var exp = '';
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
exp += "[" + k + "=" + obj[k] + "]";
}
}
expect(tpl(obj)).toBe(exp);
});
}); |
Why hasn't this been pulled? |
Need a simple and friendly object iterators please. 👍 |
Yep, we use them a lot. Laura, what's with the pull? tnx. |
Bump. |
👍 |
It would be nice if the tests where a part of the commit. @olado Any word on this making it to master? |
Bump. |
bump! @olado do you still support this project? |
+1 |
same q to @Olando, do you support this project? |
Is there a case, where you would like to iterate without checking for own properties? Please pull!!! |
👍 |
2 similar comments
👍 |
+1 |
Added support of object property iterators, e.g.
for (key in obj) {...}
Notation is similar to array iterators, '@' char is used instead of '~':
Also, this can iterate only own properties – with additional '@':