UNPKG

shivani.js

Version:

Demos for CDAC Training

52 lines (40 loc) 1.88 kB
//app.js /*var mathApp = require('./firstDemo'); var res = mathApp.add(123, 234); console.log(res); res = mathApp.sub(123, 23); console.log(res); **********************************Shoping cart Demo********************** var cart = require('./firstDemo.js'); cart.addNew({"Name":"iPhone XS", "Price": 45000}); cart.addNew({"Name":"Moto G5", "Price": 25000}); cart.addNew({"Name":"MI Note 6", "Price": 15000}); console.log(cart); //console.log(cart.getCart()) var list = cart.getCart(); debu list.forEach((e, i) => console.log(e)); ********************Using the global module***** require("./globalModule"); console.log(add(123,23)); console.log(subtract(123,23)); //Not to use too many global functions as it becomes hard to maintain for long time. U should not polute the global space in the application.... **************Using anonymous modules**************** var cart = require('./anonymousModule'); cart.addToCart({"id": 123, "name":"Mobile", "price": 4500}); cart.addToCart({"id": 124, "name":"Charger", "price": 500}); cart.addToCart({"id": 125, "name":"laptop", "price": 45500}); cart.addToCart({"id": 126, "name":"PowerBank", "price": 1000}); var basket = cart.getCart(); basket.forEach((e, i) => console.log(e.name +" priced at " + e.price)); ********************Consuming named objects******/ var module = require('./namedObjects'); var amazon = module.shoppingCart; amazon.addToCart({"id": 123, "name":"Mobile", "price": 4500}); amazon.addToCart({"id": 124, "name":"Charger", "price": 500}); amazon.addToCart({"id": 125, "name":"laptop", "price": 45500}); amazon.addToCart({"id": 126, "name":"PowerBank", "price": 1000}); console.log(amazon.getCart()); console.log("The app was developed by " + module.developedBy); console.log("This app was developed on " + module.developedOn) console.log(module.desc);