Skip to content

Commit

Permalink
for (var i : o) is now for (var i in o)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeux committed Apr 26, 2011
1 parent 0709739 commit 85959f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions example/iteration.cpp
@@ -1,7 +1,7 @@
#include "../src/javascript_start.h"

var array = {10, 42, 30};
for (var i : array) {
for (var i in array) {
std::cout << i << " - " << array[i] << std::endl;
}
// 0 - 10
Expand All @@ -15,7 +15,7 @@ var object = {
_["b"] = 2,
_["c"] = 3
};
for (var i : object) {
for (var i in object) {
std::cout << i << " - " << object[i] << std::endl;
}
// a - 1
Expand Down
3 changes: 2 additions & 1 deletion src/object.h
Expand Up @@ -91,7 +91,6 @@ class Object {
State* s;



std::map<std::string, Object>::iterator begin() {
return s->map.begin();
}
Expand All @@ -100,6 +99,8 @@ class Object {
return s->map.end();
}

#define in :

This comment has been minimized.

Copy link
@cpojer

cpojer May 3, 2011

While this will work for loops it will not work in any other context, like an if-statement or similar:

if ('property' in object);

This comment has been minimized.

Copy link
@vjeux

vjeux May 3, 2011

Author Owner

Hmm yeah you are right. I don't really know if that's possible to put both meanings with only one keyword.

It is possible to add another keyword "In" (Capital) that will be replaced by an unused infix operator such as ">>=" which will do the belonging behavior.

If you have any ideas on how to fix this, please tell :)


protected:

/* Functions */
Expand Down

0 comments on commit 85959f0

Please sign in to comment.