Javascript 如何将使用getter检索的余烬数据放入临时变量中进行处理

Javascript 如何将使用getter检索的余烬数据放入临时变量中进行处理,javascript,ember.js,Javascript,Ember.js,我有一个情况最好用这里的代码来解释 单击年份以查看问题 以下是一个示例视图: App.myView = Ember.View.extend({ date : new Date(), dateString : function(){ return this.get('date').getFullYear(); }.property().cacheable(), click : function(e){ this.$().append('<br/>clicked:

我有一个情况最好用这里的代码来解释 单击年份以查看问题

以下是一个示例视图:

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=this.get('date')

this.get('date')返回对对象的引用。您正在原始对象本身上设置年份

执行此操作时:

var tempDate=新日期(this.get('Date')

您已将原始对象克隆到新对象中。所有后续操作都不会操作原始对象。

克隆常规对象
var tempDate = new Date(this.get('date'));
tempDate.setFullYear(1988);