I'm trying to working with an IIFE and a language file to make my code localized. Problem is that the IIFE keeps saying that the variables inside the language code don't exist. I'm trying to figure out why, if someone could explain to me a bit why and how I should go about it this would be awesome!
Example
IIFE-
(function(w,d,id){
if(!d.getElementById(id)){
var fjs = d.createElement('script');
fjs.id=id;
fjs.src="url_lang_file";//this is where the language code is inserted
document.head.appendChild(fjs);
}
console.log(lang);
})(window,document,'support_lang');
Language Code-
var lang={
hello:"hello",
bye:"GoodBye"
};
Though logging just does not work and lang is "not defined" I've tried plenty of things to get this to work though anything I've tried is coming up short.
heres a fiddle to give example and I used jQuery CDN for testing purposes