Skip to content

Instantly share code, notes, and snippets.

View ktajpuri's full-sized avatar

kamlesh tajpuri ktajpuri

View GitHub Profile
@ktajpuri
ktajpuri / functional-inheritence.js
Last active August 13, 2018 08:24
Demo for functional multilevel inheritence in javascript
Object.prototype.testFunc = function () {
console.log('I am test from of global ')
}
function Person(name, age) {
this.name = name;
this.age = age;
this.printIdentity = function() {
return 'Mr. ' + this.name;
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const App = props => {
const { name, age, classes, passedProps } = props;
return (
<div className="App">
<h4>Name: {name}</h4>
const quotes = ["quote1", "quote2", "quote3", "quote4", "quote5"];
class NotFound extends React.PureComponent {
render() {
let randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
return (
<h1>
Quote: <strong>{randomQuote}</strong>
</h1>
);
const quotes = ["quote1", "quote2", "quote3", "quote4", "quote5"];
const NotFound = () => {
let randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
return (
<h1>
Quote: <strong>{randomQuote}</strong>
</h1>
);
};
@ktajpuri
ktajpuri / movie-saga.js
Last active July 14, 2018 05:15
Tesing async fetch requests in redux saga
import { put, call, takeEvery} from 'redux-saga/effects';
import { fetchMoviesApi} from './moviesApi';
export function* fetchMoviesSaga(action) {
yield put({type: 'TOGGLE_LOADING', payload: true});
try {
const movies = yield call(fetchMoviesApi);
yield put({type: 'TOGGLE_LOADING', payload: false});
yield put({type: 'LOAD_INITIAL_MOVIES', payload: movies});
} catch (e) {
async function testAsync() {
let response = await fetch('https://mock-wholesaleonline.getsandbox.com/testRedux');
let result = await response.json();
return result;
}
testAsync()
.then((result) => console.log(result))
.catch((error) => console.log(error))
@ktajpuri
ktajpuri / ES6-generator-functions.js
Last active July 14, 2018 03:55
A brief introduction to generator functions
function* generator(i) {
yield i;
yield i + 10;
}
var gen = generator(10);
console.log(gen.next().value);
// expected output: 10
@ktajpuri
ktajpuri / javascript-interview-questions.txt
Last active January 24, 2020 10:43
javascript interview question
1. What is the difference between Object.create and new.
http://frontendnotes.net/what-the-difference-between-object-create-and-new-keyword/
2. What is difference between context and scope. Thorough understanding of both.
3. What is react context.
4. What are the problems with higer order components.
5. How can you pass dynamic values as props, say dynamic refs to a multiple list items.
6. What are closures.
7. What is the problem with below code, how can you solve this.