/Coding-life

something important in javascript

Coding life

Record Something important with pictures!

Catalogue

js-important

object.keys

debounce & throttle

function debounce(fn){
    var timer;
    return function(){
        if(timer) 
        clearTimeout(timer);
        timer=setTimeout(()=>fn.call(this,arguments),1000);
    }
}

function throttle(fn){
    let timer;
    return function(){
        if(timer) 
        return;
        timer=setTimeout(()=>{fn.call(this,arguments);console.log(arguments);timer=null;},1000);
    }
}

random number array

map "v:1" to "version:1.0.0"

var objectMap=o=>keyMap=>valueMap=>{
	var newObject={};
    Object.keys(o).forEach(key => {
        newObject[keyMap[key]] =valueMap[o[key]];
    });    
    return newObject
}
let o ={v:'1'} ;
objectMap(o)({v:'version'})({'1':'1.0.0'});

nodejs

serverless

java-important