add checks for hasOwnProperty and used forEach where useful

when Object.prototype is modified (or Array.prototype, for that matter), we can no longer iterate over the keys (or elements, respectively) using `for (var ... in ...)`. Added a hasOwnProperty check for object key iteration, and used `.forEach` for array element iteration instead.
```ts
function forEach<T>(obj: {[key: string]: T}, callback: (item: T) => any): void {
    var keys = Object.keys(obj);
    for(var i = keys.length - 1; i >= 0; i--) {
          fn(obj[keys[i]]);
    }
}
```