This file contains hidden or 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
function Parent(name, address) { | |
this.fatherName = name || "unknown"; | |
this.fatherAddress = address || "Unknown"; | |
} | |
Parent.prototype.PrintParent = function () { | |
console.log("In Parent",this); | |
} | |
console.log("Creating child") |
This file contains hidden or 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
var stack = []; | |
/** | |
* get empty object node | |
*/ | |
function getObj() { | |
return { | |
data: null, | |
isleft: true, | |
left: null, |
This file contains hidden or 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
//prototype design patterns | |
exports.RunPrototype = () => { | |
TeslaModels = function () { | |
this.numWheels = 4; | |
this.manufacturer = 'Tesla'; | |
this.make = 'Model S'; | |
} | |
TeslaModels.prototype = function () { | |
var go = function () { |
This file contains hidden or 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
//Module design patterns | |
exports.RunModular = () => { | |
Employee = (() => { | |
var emp = []; | |
console.log("Modular Pattern:", this) | |
// I am private | |
function privateFunction() { | |
console.log("Private function") | |
} |
This file contains hidden or 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
exports.RunObserver = () => { | |
/** | |
* Subject could be anything, Whatsapp group, Circket feed, news letter | |
* notification | |
*/ | |
var Subject = function () { | |
//List of subscribers | |
this.observers = []; | |
return { |
This file contains hidden or 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
exports.RunSingleton = function () { | |
Printer = (() => { | |
let instance = null; | |
function createPrinter() { | |
function print() { | |
console.log("Print function", this); | |
} | |
function stop() { | |
console.log("Stop printer", this); | |
} |
This file contains hidden or 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
//npm install bluebird | |
//npm install net | |
var net = require('net'); | |
var Promise = require('bluebird'); | |
function checkConnection(host, port, timeout) { | |
return new Promise(function(resolve, reject) { | |
timeout = timeout || 10000; // default of 10 seconds | |
var timer = setTimeout(function() { |