add unique function

by Paco86

JavaScript

class Store{
	constructor(){
  	this.id = 1;
    this.cache = {};
  }
  
  add(fn){
  	if(!fn.id){
    	fn.id = this.id++;
      this.cache[fn.id] = fn
      console.log('success');
      return true;
    }
    console.log('fail');
    return false;
  }
}

let store = new Store();

function a(){}
function b(){}
function c(){}
store.add(a);
store.add(b);
store.add(a);
store.add(c);