在Javascript中,每当我手动更新rotationSetting .....例如rotation.rotationSetting = 7时,我都会尝试使其速度.steps#将由对象自动更新。
现在,我收到一个错误“Uncaught TypeError: Object.defineProperties called on non-object”,因为 rotationSetting 不是对象。我如何解决这个问题并完成我想要的?
var rotation = function() {
var rotationId;
var rotationList = [];
var rotationSetting = 3;
var speed = {
step1 : 0,
step2 : 0,
step3 : 0,
step4 : 0,
}
Object.defineProperties(rotationSetting, {
set: function(rotationSetting, speed) {
this.step1 = rotationSetting * 1000;
this.step2 = this.step1 + 1000;
this.step3 = this.step2 + this.step1;
this.step4 = this.step3 + 1000;
}
})
return {
rotationId : rotationId,
rotationList : rotationList,
rotationSetting : rotationSetting,
speed : speed,
}
}();