You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+170-2Lines changed: 170 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -404,6 +404,79 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
404
404
vm.title='Sessions';
405
405
```
406
406
407
+
- **Function Declarations to Hide Implementation Details**: Use function declarations to hide implementation details. Keep your bindable members up top. When you need to bind a function in a controller, point it to a function declaration that appears later in the file. This is tied directly to the seciton Bindable Members Up Top.
408
+
409
+
*Why?*: Placing bindable members at the top makes it easy to read and helps you instantly identify which members of the controller can be bound and used in the View. (Same as above.)
410
+
411
+
*Why?*: Placing the implementation details of a function later in the file moves that complexity out of view so you can see the important stuff up top.
412
+
413
+
*Why?*: Function declaration are hoisted so there are no concerns over using a function before it is defined (as there would be with function expressions).
414
+
415
+
*Why?*: You never have to worry with function declarations that moving `var a` before `var b` will break your code because `a` depends on `b`.
416
+
417
+
*Why?*: Order is critical with function expressions
- Notice that the important stuff is scattered in the preceeding example.
449
+
- In the example below, notice that the important stuff is up top. For example, the members bound to the controller such as `vm.avengers` and `vm.title`. The implementation details are down below. This is just esier to read.
- **Defer Controller Logic**: Defer logic in a controller by delegating to services and factories.
408
481
409
482
*Why?*: Logic may be reused by multiple controllers when placed within a service and exposed via a function.
@@ -449,7 +522,6 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
449
522
*Why?*: Pairing the controller in the route allows different routes to invoke different pairs of controllers and views. When controllers are assigned in the view using [`ng-controller`](https://docs.angularjs.org/api/ng/directive/ngController), that view is always associated with the same controller.
450
523
451
524
```javascript
452
-
453
525
/* avoid - when using with a route and dynamic pairing is desired */
454
526
455
527
// route-config.js
@@ -542,7 +614,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
542
614
543
615
- Note: [All AngularJS services are singletons](https://docs.angularjs.org/guide/services).
544
616
545
-
- **Public Members Up Top**: Expose the callable members of the service (it's interface) at the top, using a technique derived from the [Revealing Module Pattern](http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript).
617
+
- **Accessible Members Up Top**: Expose the callable members of the service (it's interface) at the top, using a technique derived from the [Revealing Module Pattern](http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript).
546
618
547
619
*Why?*: Placing the callable members at the top makes it easy to read and helps you instantly identify which members of the service can be called and must be unit tested (and/or mocked).
548
620
@@ -595,6 +667,102 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
595
667
596
668

597
669
670
+
- **Function Declarations to Hide Implementation Details**: Use function declarations to hide implementation details. Keep your acessible members of the factory up top. Point those to function declarations that appears later in the file.
671
+
672
+
*Why?*: Placing accessible members at the top makes it easy to read and helps you instantly identify which functions of the factory you can access externally.
673
+
674
+
*Why?*: Placing the implementation details of a function later in the file moves that complexity out of view so you can see the important stuff up top.
675
+
676
+
*Why?*: Function declaration are hoisted so there are no concerns over using a function before it is defined (as there would be with function expressions).
677
+
678
+
*Why?*: You never have to worry with function declarations that moving `var a` before `var b` will break your code because `a` depends on `b`.
679
+
680
+
*Why?*: Order is critical with function expressions
0 commit comments