File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -94,11 +94,13 @@ var Hash = Class.create(Enumerable, (function() {
94
94
95
95
// Our _internal_ each
96
96
function _each ( iterator , context ) {
97
+ var i = 0 ;
97
98
for ( var key in this . _object ) {
98
99
var value = this . _object [ key ] , pair = [ key , value ] ;
99
100
pair . key = key ;
100
101
pair . value = value ;
101
- iterator . call ( context , pair ) ;
102
+ iterator . call ( context , pair , i ) ;
103
+ i ++ ;
102
104
}
103
105
}
104
106
Original file line number Diff line number Diff line change @@ -182,6 +182,15 @@ new Test.Unit.Runner({
182
182
var foo = new FooMaker ( 'bar' ) ;
183
183
this . assertEqual ( "key=bar" , new Hash ( foo ) . toQueryString ( ) ) ;
184
184
this . assertEqual ( "key=bar" , new Hash ( new Hash ( foo ) ) . toQueryString ( ) ) ;
185
+ } ,
186
+
187
+ testIterationWithEach : function ( ) {
188
+ var h = $H ( { a :1 , b :2 } ) ;
189
+ var result = [ ]
190
+ h . each ( function ( kv , i ) {
191
+ result . push ( i ) ;
192
+ } ) ;
193
+ this . assertEnumEqual ( [ 0 , 1 ] , result ) ;
185
194
}
186
195
187
196
} ) ;
You can’t perform that action at this time.
0 commit comments