Open ryan-scott-dev opened 10 years ago
This is a good find.
Using window
may not be the best option for getting the global object because someone might be using Maria in a non-browser environment.
So I guess the best option would be to fetch console
before the IIFE.
I'm thinking something along the lines of:
var globalConsole = console;
var maria = (function() { // IIFE
And then in namespace.js
var maria = {};
/* DEBUG BEGIN */
// Help older browsers without the `console` host object.
var console = globalConsole || {};
console.log = console.log || function() {};
console.warn = console.warn || function() {};
console.error = console.error || function() {};
/* DEBUG END */
What are your thoughts?
The point of the IFFE is so that only one global is defined. I'd like to stay with that purity as this is important to many people.
I think the following would work.
var maria = (function(/* DEBUG BEGIN */console/* DEBUG END */) {
/* DEBUG BEGIN */
console = console || {};
//...
/* DEBUG END */
//...
}(/* DEBUG BEGIN */(typeof console === 'object') ? console : null/* DEBUG END */));
@Archytaus, any more thoughts on this?
It seems to work fine for me. I've updated the PR. I'm not sure how to apply this to AMD though, if it is an issue there as well.
It was instead trying to reference an undefined console variable scoped within the maria IIFE.