Skip to content

Instantly share code, notes, and snippets.

@elektrowolle
Last active October 5, 2016 16:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save elektrowolle/e2e578f0317a8dee52fed1a4c2463bf8 to your computer and use it in GitHub Desktop.
function sngltonFactory(_cb, _isFaultyCb){
let o = {snglton: _cb()};
_isFaultyCb = _isFaultyCb || ((c)=>typeof c == "undefined");
return function (){
const a = o;
if(_isFaultyCb(a.snglton)) {
a.snglton = _cb();
}
return a.snglton
}
}
@elektrowolle
Copy link
Author

$c = sngltonFactory(()=>$("#mainContainer"), (c)=>c.length == 0)

$c()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment