Consider this pseudo code:
(function(window){
var options = { /*where everything goes */ };
var instance = (functio
What if is_allowed
would be completely local?
(function(window){
var options = {}, is_allowed;
var instance = (function(options){
for (var i in options) {
if (options.hasOwnProperty(i)) {
this[i] = options[i];
}
}
return this;
})(options);
instance.callbacks = function(cb){
/* ... */
};
function check_allowed(){
/* check and let this function set [is_allowed] */
};
window.instance = check_allowed()
? instance
: { callbacks: function(){(alert('not allowed'));} };
} (this) );
jsBin mockup
BTW: in your code, window.instance
would be undefined
.