forked from iamshaunjp/node-js-playlist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,6 @@ | ||
//#6 Modules and require | ||
//for dividing code into logical modules i.e. separate files. | ||
//our applications can be divided into logical files. | ||
//#7 | ||
var stuff = require('./stuff');//what is exported is returned and stored in counter variable. | ||
|
||
var counter = require('./count');//what is exported is returned and stored in counter variable. | ||
|
||
console.log(counter(['shaun','crystal','ryu'])); | ||
//#4 | ||
// var time = 0; | ||
// var timer = setInterval(function(){ | ||
// time += 2; | ||
// console.log(time + ' seconds have passed'); | ||
// if (time > 5){ | ||
// clearInterval(timer); | ||
// } | ||
// },2000); | ||
|
||
|
||
// console.log(__dirname); | ||
// console.log(__filename); | ||
|
||
|
||
//#5 Function Expressions | ||
function callFunction(fun){ | ||
fun(); | ||
} | ||
//normal function statement | ||
|
||
function sayHi(){ | ||
console.log('Hi'); | ||
} | ||
|
||
sayHi(); | ||
|
||
//function expression is assigning a variable to an anonymous function | ||
|
||
var sayBye = function(){ | ||
console.log('bye'); | ||
|
||
}; | ||
|
||
sayBye(); | ||
|
||
callFunction(sayBye); | ||
|
||
callFunction(sayHi); | ||
console.log(stuff.counter(['shaun','crystal','ryu'])); | ||
console.log(stuff.adder(4,5)); | ||
console.log(stuff.adder(stuff.pi,5)); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var counter = function(arr){ | ||
return 'There are ' + arr.length + ' elements in this array'; | ||
}; | ||
var adder = function(a,b){ | ||
return `The sum of the 2 numbers is ${a+b}`; | ||
}; | ||
|
||
var pi = 3.142; | ||
// //need to explicitly say what part of this module we want available outside this module | ||
// //module.exports is an empty object, which we can use dot notation to add properties to it | ||
|
||
module.exports.counter = counter; | ||
module.exports.adder = adder; | ||
module.exports.pi = pi; | ||
|
||
// console.log(counter(['shaun','crystal','ryu'])); | ||
|
||
//ANOTHER WAY IS TO ASSIGN THE VALUES/FUNCTIONS TO MODULE.EXPORTS.PROPERTIES | ||
|
||
// module.exports.counter = function(arr){ | ||
// return 'There are ' + arr.length + ' elements in this array'; | ||
// }; | ||
// module.exports.adder = function(a,b){ | ||
// return `The sum of the 2 numbers is ${a+b}`; | ||
// }; | ||
|
||
// module.exports.pi = 3.142; | ||
|
||
//A THIRD APPROACH IS TO ASSIGN MODULE.EXPORTS TO A JAVASCRIPT OBJECT | ||
// module.exports = { | ||
// counter: counter, | ||
// adder: adder, | ||
// pi: pi | ||
}; |