Skip to content

Instantly share code, notes, and snippets.

View jineeshjohn's full-sized avatar

Jineesh jineeshjohn

View GitHub Profile
@jineeshjohn
jineeshjohn / function.js
Created August 1, 2017 11:24
Different ways to write functions
function A(){}; // function declaration
var B = function(){}; // function expression
var C = (function(){}); // function expression with grouping operators
var D = function foo(){}; // named function expression
var E = (function(){ // IIFE that returns a function
return function(){}
})();
var F = new Function(); // Function constructor
var G = new function(){}; // special case: object constructor
var H = x => x * 2; // ES6 arrow function
@jineeshjohn
jineeshjohn / sample.js
Created January 6, 2020 12:01
How to create a proxy using react create app
//step 1: Inside package.json add proxy key
// eg: "proxy": "http://jsonplaceholder.typicode.com"
//step 2: sample program to retrive from jsonplaceholder
(async()=>{
const apiData = await fetch('/users');
const json = await apiData.json();
console.log("JJJ:", json);
@jineeshjohn
jineeshjohn / launch.json
Created January 23, 2020 13:13
Debugging create react app jest test
// https://elijahmanor.com/cra-debug-vscode/
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
<script>
let counter = 0;
const debounce = (fn, delay) => {
let timeoutId;
return () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(fn, delay);
}