Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Backbone uses have a lot of places where they will initialize the function if passed to get the value, eg.</p> <pre><code> Backbone.Model.extend({ url: function() { return 'myurl.aspx'; } }); // VS Backbone.Model.extend({ url: 'myurl.aspx' }); </code></pre> <p>This is clever if you will have to make some calculation / run some conditions before you'ill know that the url is.</p> <pre><code> Backbone.Model.extend({ url: function() { if ( this.get('name') ) { return 'service1.aspx'; } else { return 'service2.aspx'; } } }); </code></pre> <hr> <p>Your first example sends an anonymous function as the first argument to <code>myFunction</code> while the second example sends an object as the first argument.</p> <pre><code>myFunction(function() { return { foo: 'bar' }; }); // function() {...} myFunction({ foo: 'bar' }); // {foo: 'bar'} function myFunction(what) { console.log(what); } </code></pre> <p>If you are talking about closures, the main difference is that you can have private variables inside closures:</p> <pre><code>var setGet = (function() { var v = null; return { get: function() { return v; }, get: function(val) { v=val; }, }; }); // VS: var setGet = { v: null, get: function() { return this.v; }, get: function(val) { this.v; }, }; </code></pre> <p>In the first example you can't access the variable <code>v</code> without using <code>.get</code>/<code>.set</code> on <code>setGet</code> while in the 2. example i can simple change it by setting <code>setGet.v = 'new_val';</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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