Skip to content

Commit a54ee98

Browse files
author
Ashfaq
committed
module patters
1 parent c468ebc commit a54ee98

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

ModularPatters/app.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const greet = require("./moduler/Pattern1");
2+
greet();
3+
4+
const greet2 = require("./moduler/pattern2");
5+
greet2.greet();
6+
7+
const greet2_1 = require("./moduler/pattern2").greet;
8+
greet2_1();
9+
10+
// Using ES6 Destructuring.
11+
const { greet: greet2_2 } = require("./moduler/pattern2");
12+
greet2_2();
13+
14+
const greet3 = require("./moduler/pattern3");
15+
greet3.greet();
16+
17+
// we are changing the name property of greet3 Object. It will affect all the requires.
18+
greet3.name = "changed Hello !!";
19+
20+
const greet3_1 = require("./moduler/pattern3");
21+
22+
greet3_1.greet(); // Ashfaq Ansari
23+
24+
const greet4 = require("./moduler/pattern4");
25+
var grt4 = new greet4();
26+
grt4.greet();
27+
// we are changing the name property of grt4 Object. it won't affect the further requires.
28+
grt4.name = "changed Hello !!!";
29+
30+
const greet4_1 = require("./moduler/pattern4");
31+
var grt4_1 = new greet4_1();
32+
grt4_1.greet();
33+
34+
const greet5 = require("./moduler/pattern5");
35+
greet5.greet();
36+
37+
const greet5_1 = require("./moduler/pattern5").greet;
38+
greet5_1();
39+
40+
const { greet: greet5_2 } = require("./moduler/pattern5");
41+
greet5_2();

ModularPatters/moduler/Pattern1.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
console.log("\npattern1 is required");
2+
3+
function greet() {
4+
console.log("Hello");
5+
}
6+
7+
module.exports = greet;

ModularPatters/moduler/Pattern2.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
console.log("\npattern2 is required");
2+
3+
function greet() {
4+
console.log("Hello!");
5+
}
6+
7+
module.exports.greet = greet;

ModularPatters/moduler/Pattern3.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
console.log("\npattern3 is required");
2+
3+
function Greet() {
4+
this.name = "Hello !!",
5+
this.greet = function() {
6+
console.log(this.name);
7+
};
8+
}
9+
10+
module.exports = new Greet();

ModularPatters/moduler/Pattern4.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
console.log("\npattern4 is required");
2+
3+
function Greet(){
4+
this.name = "Hello !!!",
5+
this.greet = function(){
6+
console.log(this.name);
7+
}
8+
}
9+
10+
module.exports = Greet;

ModularPatters/moduler/Pattern5.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
console.log("\npattern5 is required ");
2+
3+
module.exports = {
4+
greet: function(){
5+
console.log("Hello!!!!");
6+
}
7+
}

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "module_patterns",
3+
"version": "0.1.0",
4+
"description": "looking a differnt module patters",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"node",
11+
"modules",
12+
"commonPattern",
13+
"commonJS"
14+
],
15+
"author": "mohammedashfaq.nitk@gmail.com",
16+
"license": "ISC"
17+
}

0 commit comments

Comments
 (0)