Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular.forEach fails silently when passed 'undefined' reference #9062

Closed
Trendy opened this issue Sep 12, 2014 · 3 comments
Closed

angular.forEach fails silently when passed 'undefined' reference #9062

Trendy opened this issue Sep 12, 2014 · 3 comments

Comments

@Trendy
Copy link

Trendy commented Sep 12, 2014

Angular's implementation of forEach fails silently when passed and undefined reference. Example here: http://plnkr.co/3TrVkuC6mLi8pAapIWvn

Native implementations throw a TypeError when the reference is undefined: http://plnkr.co/2KfVwdIuRuno0DWwmV7N

@caitp
Copy link
Contributor

caitp commented Sep 12, 2014

This strikes me as a non-bug, since angular's forEach is not a polyfill of ES5 forEach

@Trendy
Copy link
Author

Trendy commented Sep 13, 2014

I would agree, but it isn't something you'd expect. I was refactoring some code to use native for loops today and had tests suddenly fail because the previous forEach loop was silently failing when the array wasn't being defined.

Maybe it is supposed to fail silently by design, but I think that should be mentioned in documentation at the very least.

@caitp
Copy link
Contributor

caitp commented Sep 15, 2014

I'm going to close this because I don't think we're going to change this behaviour (although it's always possible I'm wrong) --- however you're welcome to submit a docs fix to indicate that forEach(undefined) is perfectly acceptable

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants