Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maria not using the browser console for debugging. #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ryan-scott-dev
Copy link

It was instead trying to reference an undefined console variable scoped within the maria IIFE.

It was instead trying to reference an undefined console variable scoped within the maria IIFE.
@petermichaux
Copy link
Owner

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.

@ryan-scott-dev
Copy link
Author

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?

@petermichaux
Copy link
Owner

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 */));

@petermichaux
Copy link
Owner

@Archytaus, any more thoughts on this?

@ryan-scott-dev
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants