Implementing For Each in JScript

2007-04-24 11:01:30 +0000

function forEach(enumerable, delegate)
{
    for (var enumerator = new Enumerator(enumerable); !enumerator.atEnd(); enumerator.moveNext())
    {
        delegate(enumerator.item());
    }
}

Used like this:

forEach(employees,
        function(employee)
        {
            WScript.Echo(employee.Salary);
        }
    );