1

The following is a part of my bb view:

define(['backbone', 'tools/logger', 'icanhaz', 'view/loader', 'text!template/root.ich',
    'view/users', 'view/chart/monthly_balance', 'datatables'],
function(Backbone, logger, ich, loader, template,
    UsersView, MonthlyBalanceChartView) {

    // here I can see both `loader` and `template` variables

    'use strict';

    return Backbone.View.extend({

        [...]

        initialize: function(options) {
            logger.init('root');
            // I can't see `loader` and `template` here
        },

        [...]

    });
});

The problem is, that I can't see two variables inside the view's initialize method and I've got no idea why. I thought it should be caught into a closure. I make a test using google chrome's developer tools breakpoint. just before the use strict, I can see everything (the loader and template variables are set). All other variables are accessible.

For example, the entire loader file is:

define(
    ['icanhaz', 'tools/logger'],
    function(ich, logger) {
        return {
            loadTemplate: function(tpl) {
                $(tpl).each(function() {
                    if (this.outerHTML) {
                        ich.addTemplate(this.id, $(this).text());
                        logger.log('LOADED', this.id);
                    }
                });
            }
        };
    });

What is the reason for those vars to be undefined?

ducin
  • 25,621
  • 41
  • 157
  • 256
  • 1
    Unlikely, this will indeed create a closure. Did you actually reference them in your code, or are you only looking at the scope in devtools? If not, [they might have been garbage-collected](http://stackoverflow.com/a/8667141/1048572). If you do reference them, some code in the `[…]` might have nulled them. – Bergi Jul 22 '14 at 18:37
  • @Bergi is right. If you don't actually reference the variables, they get garbage-collected. My co-worker was having this exact problem! – Russ Sep 24 '14 at 20:59

1 Answers1

0

Open the console, and on network tab, try to fund if this js file is loaded

Maybe you'll need to use the shim command to load non modules files

Take a read here for shim examples.. https://github.com/requirejs/example-jquery-shim

Hope it helps.

rcarvalho
  • 790
  • 1
  • 4
  • 14