JSFiddle - React, Tailwind, and code Playground

by mediastuttgart

HTML

<script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.5.min.js"></script>

JavaScript

// App
App = Ember.Application.create();

// Foo controller
App.Foo = Ember.ArrayController.create({
        init : function () {
                var that = this;

                // this.addObserver('foo', App.Bar.baz);
                ///> Doesn't work because App.Bar is undefined

                // Wrapped in a function works
                this.addObserver('foo', function () {
                        App.Bar.baz();
                });

                $(window).bind('resize', function () {
                        // Other possibilities to access App.Foo
                        // instead of preserving scope with "that"?
                        that.set('foo', $(window).width());
                });
        }
});

// Bar controller
App.Bar = Ember.ArrayController.create({
        baz : function () {
                // Is this the right way to access App.Foo?
                Ember.Logger.log(App.Foo.get('foo'));
        }
});