Looking for an explanation of some code in Backbone.fetch ()

I often read source code as a good resource for learning programming. I looked at the Backbone.Model method fetch()and had this question, I was hoping that someone could shed some light.

Here is the fetch () method:

// ---------------------------------------------------------------------
// Fetch the model from the server. If the server representation of the
// model differs from its current attributes, they will be overriden,
// triggering a `"change"` event.
fetch: function(options) {
  options = options ? _.clone(options) : {};
  if (options.parse === void 0) options.parse = true;
  var success = options.success;
  options.success = function(model, resp, options) {
    if (!model.set(model.parse(resp, options), options)) return false;
    if (success) success(model, resp, options);
  };
  return this.sync('read', this, options);
}

My question is: what is the point of the if condition ? just evaluates to 'undefined', so is it a shortcut for testing if the property is not defined? And if so, does it have any advantages over the standard operator , which I find more semantic and readable? if (options.parse === void 0)... void 0 (typeof options.parse === 'undefined')

+3
source share
1 answer

, void 0. undefined . , .

: JavaScript` undefined `vs` void 0`

0

All Articles