0

私はデモコントローラを持っています:

import Ember from 'ember';

export default Ember.Controller.extend({
  firstName: 'Bob',
  lastName: 'Smith',

  emailAddress: 'bobsmith@gmail.com',

  fullName: Ember.computed('firstName', 'lastName', function() {
    console.log('executed!');
    return `${this.get('firstName')} ${this.get('lastName')}`;
  }),

  actualEmailAddress: Ember.computed('emailAddress', function() {
    console.log('actualEmailAddress function is called: ', this.get('emailAddress'));
  })
});

ブラウザーの localhost でアプリを実行しているときに、ember インスペクターを開いて実行します。

$E.get('actualEmailAddress')

これは以下を返します:

actualEmailAddress function is called: bobsmith@gmail.com

しかし、もう一度実行すると、undefined

走るときも同じ$E.get('fullName')

戻る

executed!
"Bob Smith"

しかし、もう一度実行すると、返されるBob Smithのではなく、console.log

なぜこうなった?

ありがとうございました!

4

3 に答える 3