我正在创建一个包含一些天文计算的网页,其中涉及用户能够更改日期/时间/纬度/经度/等以及相应地重新计算的页面。
我创建了一个对象 - 一个全局对象 - 具有许多属性和用于更新这些属性的方法,但现在我对此提出质疑......
当我需要重新计算或将对象不断地放在内存中时,读取页面元素是否更好/更有效。
这是对象定义:
function TIME_OBJ () {
var d = new Date();
//Properties
this.LHour = d.getHours();
this.LMinute = d.getMinutes();
this.LSecond = d.getSeconds();
this.TZone = (d.getTimezoneOffset() / 60) * -1;
this.LDay = d.getDate();
this.LMonth = d.getMonth() + 1;
this.LYear = d.getFullYear();
this.UHours = 0;
this.UMinutes = 0;
this.USeconds = 0;
this.UDay = 0;
this.UMonth = 0;
this.UYear = 0;
this.UTString = "";
this.GSTHour = 0;
this.GSTMinute = 0;
this.GSTSecond = 0;
this.GSTString = "";
this.LSTHour = 0;
this.LSTMinute = 0;
this.LSTSecond = 0;
this.LSTString = "";
this.GDay = 0;
this.GMonth = 0;
this.GYear = 0;
this.GHour = 0;
this.GMinute = 0;
this.GSecond = 0;
this.GString = "";
this.LJD = 0;
this.UJD = 0;
this.LMJD = 0;
this.UMJD = 0;
this.LDoW = 0;
this.UDoW = 0;
this.LDayN = 0;
this.UDayN = 0;
this.LatD = 52;
this.LatM = 0;
this.LatS = 0;
this.LatNS = "S";
this.LatDD = 0;
this.LonD = 0;
this.LonM = 30;
this.LonS = 0;
this.LonEW = "W";
this.LonDD = 0;
//Methods
this.UpdateAll = UpdateAll;
this.UpdateDate = UpdateDate;
this.SetClean = SetTimeClean;
this.GetUT = UpdateUT;
this.GetLJD = UpdateJD;
this.GetUJD = UpdateJD;
this.GetLMJD = UpdateMJD;
this.GetUMJD = UpdateMJD;
this.GetLDoW = UpdateDoW;
this.GetUDoW = UpdateDoW;
this.GetLDayN = UpdateDayN;
this.GetUDayN = UpdateDayN;
this.GetGrDate = UpdateGD;
this.GetGST = UpdateGST;
this.GetLST = UpdateLST;
this.GetDecPos = UpdateDecPos;
this.Dirty = false;
}
因此,如果日期发生变化,这将影响本地恒星时、格林威治时间、世界时间、日出/日落、月出/日落等。这样,如果我正在读取页面元素,我将不得不进行许多 getElementById 调用来获取数据,而不是拥有一个已设置属性的全局对象,我只需要在计算完成后对元素进行页面处理。
欣赏你的想法.... Daz
PS DOM 是页面的正确术语吗?