Skip to content

Commit 20df6a2

Browse files
committed
adds block about angular low-level functions
Update README.md Update README.md Addressed comments made in #768
1 parent 42185df commit 20df6a2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

a1/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
5656
1. [Routing](#routing)
5757
1. [Task Automation](#task-automation)
5858
1. [Filters](#filters)
59+
1. [Low Level Functions](#low-level-functions)
5960
1. [Angular Docs](#angular-docs)
6061

6162
## Single Responsibility
@@ -3268,6 +3269,34 @@ Use [Gulp](http://gulpjs.com) or [Grunt](http://gruntjs.com) for creating automa
32683269
32693270
**[Back to top](#table-of-contents)**
32703271
3272+
## Low Level Functions
3273+
3274+
Angular 1.x ships with some [helper functions](https://docs.angularjs.org/api/ng/function) that are found within JavaScript natively. In such cases we should favor usage of native JavaScript functions instead of Angular's helper functions. In other cases where functionality is not found in JavaScript natively, we should turn to utility libraries such as [lodash](https://lodash.com/docs) to fill-in the gaps. Here are some examples:
3275+
3276+
|Replace | With | |
3277+
|---|---|---|
3278+
|`angular.isArray()` | `Array.isArray()` | |
3279+
|`angular.forEach()` | `Array.prototype.forEach()` | _for arrays_ |
3280+
|`angular.forEach()` | `_.forEach()` | _for objects_ |
3281+
|`angular.isUndefined()` | `_.isUndefined()` | |
3282+
|`angular.copy()` | `_.cloneDeep()` | |
3283+
|`angular.extend()` | `Object.assign()` | _available in ES2015+_ |
3284+
3285+
3286+
###### [Style [Y500](#style-y500)]
3287+
3288+
- Avoid using Angular low-level functions such as `angular.copy()`, `angular.extend()` or even `angular.isUndefined()`.
3289+
3290+
*Why?*: You can replace a lot Angular's low-level functions with native ES2015+ functionality such as [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) for copying objects and the [Spread Syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator#Copy_an_array) for copying arrays _(ie. `[...arr1]`)_.
3291+
3292+
*Why?*: This will ease the process of upgrading to Angular 2 as it does not ship with these helper functions.
3293+
3294+
- Note: Favor usage of functions that are available in JavaScript natively, then resort to using a utility library like [lodash](https://lodash.com/docs) when what you need is not available.
3295+
3296+
- Note: you might need to use a [polyfill](https://babeljs.io/docs/usage/polyfill/) to take advantage the latest features of JavaScript for better browser support.
3297+
3298+
**[Back to top](#table-of-contents)**
3299+
32713300
## Filters
32723301
32733302
###### [Style [Y420](#style-y420)]

0 commit comments

Comments
 (0)