如何缓存JavaScript Date对象? [英] How to cache the JavaScript Date object?

查看:84
本文介绍了如何缓存JavaScript Date对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Date.js 来支持我的网络应用中的多种文化。这里的问题是date.js有这样的代码。

I am using Date.js to support many cultures in my web app. The problem here is that date.js has code like this.

  Date.prototype._toString = Date.prototype.toString;
  Date.prototype.toString = function () {
    //doing something
        return this._toString();
   }

当我使用其他文化文件时,它也包含此定义。所以逻辑上我的doc有这个

when I use another culture file, it also contains this definition. so logically my doc has this

//date.js
     Date.prototype._toString = Date.prototype.toString;
     Date.prototype.toString = function () {
     //doing something
         return this._toString();
     }
     //date-fr-FR.js
     Date.prototype._toString = Date.prototype.toString;
     Date.prototype.toString = function () {
         //doing something
         return this._toString();
     }

我指的是date.js和date-fr-FR.js在我的网络应用程序中。

I am refering to both date.js and date-fr-FR.js in my web app.

问题是当我使用toString函数 var d = new Date()。toString(); 由于递归调用,它会抛出堆栈空间 msg。有没有办法缓存
原始Date对象并将其休息,因为我不想从doc中删除date.js

The problem is when I use the toString function var d = new Date().toString(); it throws an Out of stack space msg, because of the recursive calls. Is there any way to cache the orginal Date object and rest it back, because i don't want to remove date.js from doc

推荐答案

不是同时包含 date.js date-fr-FR.js ,只需要包含 fr-FR.js 文件来更改文化,您可以在Datejs-all-Alpha1.zip文件的src / globalization文件夹中找到它。 fr-FR.js文件只包含特定于文化的数据,它应该覆盖date.js中已包含的内容,而不重新定义功能。

Instead of including both date.js and date-fr-FR.js, you only need to include the fr-FR.js file to change the culture, which you will find in the src/globalization folder in the Datejs-all-Alpha1.zip file. The fr-FR.js file only contains the culture specific data, and it should override what is already included in date.js, without redefining the functionality.

这篇关于如何缓存JavaScript Date对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆