Skip to content

Instantly share code, notes, and snippets.

View bjangid20's full-sized avatar
🌎
Focusing

Bharat Jangid bjangid20

🌎
Focusing
View GitHub Profile
@bjangid20
bjangid20 / output
Created June 16, 2021 05:25
Implement bind in js
Function.prototype.mybind = function (context, ...args1) {
let fn = this;
return function (...arg2) {
fn.apply(context, [...args1, ...arg2])
}
};
@bjangid20
bjangid20 / output
Created June 15, 2021 12:29
multiple async call and get result of sucess and failure call both (Don't turminate after a failure)
var urls = [
'https://api.github.com/users/iliakan',
'https://remy.com',
'https://api.github.com/users/jeresig'
];
Promise.all(
urls.map(url =>
fetch(url)
.then(r => r.json())
@bjangid20
bjangid20 / output
Last active June 15, 2021 12:31
Execute last async call only and ignore other calls
var clear;
function calling (param, time) {
clearTimeout(clear);
var promise = new Promise(function(resolve, reject) {
clear = setTimeout(() => resolve(param), time);
});
promise.then(r => console.log('Do whatever you want', r));
}