ここのコードで最もよく説明されている状況がありますhttp://jsfiddle.net/sabithpocker/EsF4R/34/ 年をクリックして問題を確認してください。
サンプル ビューを次に示します。
App.myView = Ember.View.extend({
date : new Date(),
dateString : function(){
return this.get('date').getFullYear();
}.property().cacheable(),
click : function(e){
this.$().append('<br/>clicked: now this.get("date") = ' + this.get('date').getFullYear());
var tempDate = this.get('date');
tempDate.setFullYear(1988);
this.$().append("<br/>tempDate :" + tempDate.getFullYear() + " & " + "this.get('date') :" + this.get('date').getFullYear());
}
});
クリックイベント内で、保存のために日付を一時変数に保存しようとしていますが、一時変数で作業すると、変更が元の変数に反映されます。それは私が望んでいないことです。
私は次のことでこれを克服しました:
var tempDate = new Date(this.get('date'));
しかし、私はここで何が間違っていますか?