Skip to content

Commit 29db538

Browse files
committed
Update the module pattern
1 parent cf48a48 commit 29db538

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,17 @@ function ChildCtrl($scope, User) {
872872
}
873873
```
874874

875-
The most appropriate location to verify that the user is already authenticated is not the main controller. Anyway, this example aims to illustrates the most trivial way to reuse logic by using a base controller.
875+
This example aims to illustrates the most trivial way to reuse logic by using a base controller, anyway in production applications I don't recommend you to put your authorization logic in the controllers. The access to the different routes could be determined on a higher level of abstraction.
876876

877877
The `ChildCtrl` is responsible for handling actions such as clicking the button with label `"Click"` and exposing the model to the view, by attaching it to the scope.
878878

879879
### Others
880880

881881
#### Module Pattern
882882

883-
This is actually not a design pattern from Gang of Four, neither one from P of EAA. This is a tranditional JavaScript pattern, which main goal is to provide encapsulation and privacy.
883+
This is actually not a design pattern from Gang of Four, neither one from P of EAA. This is a traditional JavaScript pattern, which main goal is to provide encapsulation and privacy.
884884

885-
Using the module pattern you can achieve privacy based on the JavaScript's functional lexical scope. Each module may have one or more private members, which are hidden in the local scope of a function, and an object, which exports the public API of the given module:
885+
Using the module pattern you can achieve privacy based on the JavaScript's functional lexical scope. Each module may has zero or more private members, which are hidden in the local scope of a function. This function returns an object, which exports the public API of the given module:
886886

887887
```javascript
888888
var Page = (function () {
@@ -907,9 +907,9 @@ var Page = (function () {
907907

908908
In the example above we have IIFE (Immediately-Invoked Function Expression), which after being called returns an object, with two methods (`setTitle` and `getTitle`). The returned object is being assigned to the `Page` variable.
909909

910-
In this case the user of the `Page` object does not has direct access to the `title` variable, which is defined inside the local scope of the IIFE.
910+
In this case the user of the `Page` object doesn't has direct access to the `title` variable, which is defined inside the local scope of the IIFE.
911911

912-
The module pattern is very useful when defining services in AngularJS. Using this pattern we can simulate (and actually have) privacy:
912+
The module pattern is very useful when defining services in AngularJS. Using this pattern we can simulate (and actually achieve) privacy:
913913

914914
```javascript
915915
app.factory('foo', function () {
@@ -930,7 +930,7 @@ app.factory('foo', function () {
930930
});
931931
```
932932

933-
Once we want to inject `foo` inside any other component we won't be able to use the private methods, but only the public ones. This solution is extremely powerful especially when one is building a third-party library.
933+
Once we want to inject `foo` inside any other component we won't be able to use the private methods, but only the public ones. This solution is extremely powerful especially when one is building a reusable library.
934934

935935
## AngularJS application Patterns
936936

0 commit comments

Comments
 (0)