vendredi 1 septembre 2017

How is modifying a class in `reopenClass` different than extending a class with `extend`?

I'm playing with the fixture adapter in Ember.js.

This:

let cars = DS.Model.extend({
  make: attr('string'),
  model: attr('string'),
  year: attr('string'),
  FIXTURES: [
    {
      id: 1,
      model: 'foo',
      make: 'bar',
      year: '2001'
    }
  ]
});

Throws "unable to find fixtures"

Whereas this:

let cars = DS.Model.extend({
  make: attr('string'),
  model: attr('string'),
  year: attr('string'),
});

cars.reopenClass({
  FIXTURES: [
    {
      id: 1,
      model: 'foo',
      make: 'bar',
      year: '2001'
    }
  ]
});

Works great. I would expect them to be the same, though, what's the difference?




Aucun commentaire:

Enregistrer un commentaire