Skip to content

Instantly share code, notes, and snippets.

View g-akshay's full-sized avatar
🎯
Bullseye

Akshay Gundewar g-akshay

🎯
Bullseye
View GitHub Profile
@g-akshay
g-akshay / ModulePattern.md
Last active February 21, 2017 15:41
Revealing Module Pattern
  • Defined as a way to provide both private and public encapsulation for classes
  • functions/properties are encapsulated using closures
  • Start private attribute names with underscore (convention)

Pros

  • Reduces chance of function name conflict with other devs
  • You can return specific function based on some configuration or environment
  • Revealing pattern makes it more clear at the end of module about the properties which are made public.
@g-akshay
g-akshay / constructor.js
Last active February 21, 2017 14:54
Constructor Pattern
function Person( name, age, weight ) {
this.name = name;
this.age = age;
this.weight = weight;
}
// a single instance of toString method will be shared amongst all the person objects
@g-akshay
g-akshay / spammer.js
Created February 19, 2017 09:26
Whatsapp spammer !!! works on whatsApp web version
var contactName = '',
message = 'this is spamming 😂😂',
counter = 1,
frequency = 10;
var count = 0,
interval = setInterval(function(){
//selectContact(contactName);
@g-akshay
g-akshay / Prototype Chain.js
Last active April 20, 2018 10:33
Extending JS object using prototype chain
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name + '-parent';
}
function Author(name, books) {
Author.superclass.constructor.call(this, name);
this.books = books;
@g-akshay
g-akshay / ClosureLoopingBugFix2.js
Last active May 9, 2018 06:12
Code from Closure Blog
'use strict';
function closureLoopBug() {
for (let i = 0; i < 5; i++) {
setTimeout(function() {
console.log('Value of i: ' + i);
}, 1000);
}
}
@g-akshay
g-akshay / ClosureLoopingBugFix1.js
Last active May 9, 2018 06:09
Code from Closure Blog
function myTimeout(i){
setTimeout(function() {
console.log('Value of i: ' + i);
}, 1000);
}
function closureLoopBug() {
var i;
for (i = 0; i < 5; i++) {
@g-akshay
g-akshay / ClosureLoopingBug.js
Last active May 9, 2018 06:09
Code from Closure Blog
function closureLoopBug() {
var i;
for (i = 0; i < 5; i++) {
setTimeout(function() {
console.log('Value of i: ' + i);
}, 1000);
}
}
@g-akshay
g-akshay / closureExample.js
Last active February 19, 2017 07:46
Code from Closure Blog
function payBill(){
// valid promo codes for current month to get discount on total payable amount
var validCodes = ['FIRST50', 'OFF10', 'APP15', 'WALLET'];
function checkCode(promoCode){
if( validCodes.indexOf(promoCode) !== -1 )
{
console.log('Hurray!! You got a discount.')
@g-akshay
g-akshay / functionAssignment.js
Last active February 19, 2017 07:50
Code from Closure Blog
var someobject = function(){
. . .
};
@g-akshay
g-akshay / varaibleScope.js
Last active February 19, 2017 07:46
Code from Closure Blog
var global = 10, // some number
anotherGlobal = 100, // some number
someObject; // just declared
function anotherGlobal(){
console.log('I am a function.');
}
function someObject(){
global = 15;