lundi 25 janvier 2016

Overridden function in reopened class is undefined

I would like to override Model.save() globally for all models. So I created initializer...

import DS from 'ember-data';

export function initialize(appInstance) {
  DS.Model.reopen({
    save() {
      return this._super(...arguments);
    }
  });
}

export default {
  name: 'model-save',
  initialize: initialize
};

Looks good and works fine if chrome console is opened. With closed console the save() is undefined.

const model = this.get('model');
console.log(model);
console.log(model.save);

And console output:

stack

How is this even possible?




Aucun commentaire:

Enregistrer un commentaire