Skip to content

Instantly share code, notes, and snippets.

@binary10ve
Created February 3, 2019 11:05
Show Gist options
  • Save binary10ve/48da7f2a39333d0340c166f48950be96 to your computer and use it in GitHub Desktop.
Save binary10ve/48da7f2a39333d0340c166f48950be96 to your computer and use it in GitHub Desktop.
const getAppEnv = (function(){
class AppEnv{
constructor(platform, buildVersion){
this.platform = platform;
this.buildVersion = buildVersion;
this.cacheEnabled = false;
}
enableCache(){
this.cacheEnabled = true;
}
}
let appEnv = null;
return function(){
if(appEnv == null){
console.log("Fetching for the first Time");
appEnv = new AppEnv("unix","10.1.1");
}else{
console.log("Fetching second Time");
}
return appEnv;
}
}());
p = getAppEnv();
console.log(p.cacheEnabled);
c = getAppEnv();
console.log(c.cacheEnabled);
p.enableCache()
console.log(p.cacheEnabled);
console.log(c.cacheEnabled);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment