Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone: need help passing a URL to a self-invoking function
    text
    copied!<p>I was given this block of code to work with from a <a href="https://stackoverflow.com/questions/14512551/backbone-console-log-returning-collection-and-undefined">previous post</a>:</p> <pre><code>;(function(){ var mythings = {}; function initializer($, _, Backbone, tableModel){ return Backbone.Collection.extend({ url: 'main-contact', &lt;!-- this used to be this.url. model: tableModel, initialize: function(models, options) { this.fetch(); } }); } define([ 'jquery', 'underscore', 'backbone', 'models/tableModel' ], function($, _, Backbone, tableModel) { if (!mythings.tablesCollection){ // this will be done on first run. mythings.tablesCollection = initializer($, _, Backbone, tableModel); } // all others will just return same exact instance of collection class return mythings.tablesCollection; }); })(); </code></pre> <p>First, what does the semicolon at the beginning of the block mean? Second, I need to pass in a URL at runtime in my route, like this:</p> <pre><code>var t = new tablesCollection(null, { url: 'main-contact'} ); </code></pre> <p>This is what I've been doing up until now, when I'm trying to recreate this project as AMD. How can I pass in the URL at runtime, like this into the block of self-invoking code?</p> <p>EDIT:</p> <pre><code>define([ 'jquery', 'underscore', 'backbone', 'models/tableModel', 'collections/tablesCollection', 'views/tablesView' ], function($, _, Backbone, tableModel, tablesCollection, tablesView) { require(['collections/tablesCollection'], function(tablesCollection) { var t = new tablesCollection(null, {url: 'main-contact'}); var tables = new tablesView({ collection: t, template: 'main-contact-template'}); $('#web-leads').html(tables.render().el); }); </code></pre> <p>});</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload