Proper forEach polyfill

The listed polyfill did not handle all cases, such as `null` or callbacks that are not of type `function`. This is the proper implementation as defined by the MDN.