Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / closure-loop.js
Created June 24, 2020 04:04
Closure inside loop
for(var i=0; i<5; i++) {
(function (i){
setTimeout(function() {
console.log(i);
}, 0);
})(i);
}
@night-fury-rider
night-fury-rider / observer-design-pattern.ts
Created July 9, 2020 12:30
Design Pattern - Observer
const employeeObservable = new Rx.Observable(employeeObserver => {
employeeObserver.next('Yuvraj Patil');
employeeObserver.next('Ganesh Gaitonde');
});
employeeObservable.subscribe(employeeName => {
console.log('Promoted Employee: ', employeeName);
});
@night-fury-rider
night-fury-rider / npm-package.json
Last active March 26, 2021 05:26
NPM Package - package.json
{
"name": "@uv-tech/util",
"version": "1.0.5",
"description": "It is a utility package intended to be used for doing common utilities.",
"main": "lib/index.js",
"type": "lib",
"scripts": {
"build": "tsc -p ."
},
"keywords": [
@night-fury-rider
night-fury-rider / shot-hand.js
Created September 9, 2020 04:01
Without Short hand condition
if(isVisible) {
console.log('We should use the braces even if there is only one statement in block');
}
@night-fury-rider
night-fury-rider / design-pattern-singletone.js
Last active September 9, 2020 09:36
Design Pattern - Singletone
var TaskManager = (function(){
var taskManager = null;
function createInstance(id) {
if(taskManager === null) {
taskManager = new Object();
taskManager.id = id;
return taskManager;
}
return taskManager;
@night-fury-rider
night-fury-rider / design-pattern-constructor.js
Last active September 9, 2020 10:20
Design Pattern - Constructor
var Person = function(personName) {
this.name = personName;
};
var person1 = new Person('Yuvraj');
var person2 = new Person ('Arya');
console.log(person1.name); // Yuvraj
console.log(person2.name); // Arya
@night-fury-rider
night-fury-rider / design-pattern-prototype.js
Created September 9, 2020 10:48
Design Pattern - Prototype
var Cricketer = function(name, runs) {
this.name = name;
this.runs = runs;
};
Cricketer.prototype.getPlayerDetails = function() {
return this.name + ' has scored ' + this.runs + ' runs';
}
var player1 = new Cricketer('Sachin', 18426);
@night-fury-rider
night-fury-rider / design-pattern-module.js
Last active September 17, 2020 04:06
Design Pattern - Module
var Person = function(personName) {
var age = 30; // age will not be accessible outside of Person block
var name = 'Yuvraj';
return {
getName: function() {
return name;
}
}
};
@night-fury-rider
night-fury-rider / design-pattern-enhanced-module.js
Last active September 17, 2020 04:06
Design Pattern - Enhanced Module
var Person = function(personName) {
var age = 30; // age will not be accessible outside of Person block
var name = 'Yuvraj';
function getName() {
return name;
}
// This return code block is more clean than that of module pattern
return {
@night-fury-rider
night-fury-rider / design-pattern-factory.js
Created September 9, 2020 11:24
Design Pattern - Factory
var Mobile = function(size) {
this.displaySize = size;
};
var Tablet = function(size) {
this.displaySize = size;
};
var Desktop = function(size) {
this.displaySize = size;