shivani.js
Version:
Demos for CDAC Training
56 lines (46 loc) • 965 B
JavaScript
//firstDemo.js
/*function sayHello(){
return "Hello world";
}
function addFunc(first, second){
return first + second;
}
console.log(addFunc(123, 234));
// console.log(sayHello());
********************Creating the first Module to export**************
module.exports = (function(){
function addFunc(first, second){
return first + second;
}
function subFunc(first, second){
return first - second;
}
return{
add : addFunc,
sub : subFunc
}
})();
***************shopping cart Module***************************/
module.exports = (function(){
var cart = [];
function addItem(item){
cart.push(item)
}
function getAll(){
return cart;
}
function remove(id){
for (var i = 0; i < cart.length; i++) {
if(cart[i].id == id){
cart.splice(i, 1);
return;
}
}
}
//they are private to the module...
return {
addNew : addItem,
delete : remove,
getCart : getAll
}
})();