-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
34 lines (29 loc) · 825 Bytes
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'
/**
* Module Pattern:
* Can be a Object Literal or Wrap into a function.
* The base difference between MODULE and CONSTRUCTOR patterns
* is when use MODULE, we have only ONE (Eg. A Service) while CONSTRUCTOR
* we have SOME (Eg. User, Task)
*/
// Responsible for All repository Calls
let repo = function () {
// Module private variable
let db = {
name: 'DB_1'
}
// REVEALING MODULE PATTERN
// Now i can see the methods of this module
let get = function (id) {
return {name: 'Task #1'}
}
return {
get: get, // use Revealing module pattern
save: function (task) {
return {name: task.name, status: 'OK', database: db.name}
}
}
}
// There is no problem to execute this function,
// since the return will be methods and we have no Constructors.
module.exports = repo()