简体   繁体   English

为什么当我使用JQuery DatePicker时Google Code Prettifier停止工作(反之亦然)

[英]Why does Google Code Prettifier stop working when I use JQuery DatePicker (or vice versa)

If the Google Code Prettifier (or JQuery Syntax Highlighter ) is being used in the same page as the JQuery DatePicker , neither will work properly. 如果在与JQuery DatePicker相同的页面中使用了Google Code Prettifier (或JQuery语法荧光笔 ),则两者均无法正常工作。 Why is this? 为什么是这样?

Because they both monkey patch a now method onto the native Date object! 因为他们俩都在本地Date对象上添加了now方法!

Prettify does this: 美化做到这一点:

var clock = Date;
if (!clock['now']) {
  clock = { 'now': function () { return +(new Date); } };
}

DatePicker does this: DatePicker这样做:

Date.now=function(){return new Date();}

So Prettify's returns an int representation of the Date (so that it can add on some ms) while DatePicker returns a Date. 因此,Prettify的返回Date的int表示形式(以便可以在某些ms上添加),而DatePicker返回一个Date。

(IMO this kind of thing is outrageous in two such commonly-used libraries.) (在两个这样的常用库中,IMO这类事情太过残酷了。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么谷歌代码美化器拒绝使用 XSLT? - Why does the google code prettifier refuse to work with XSLT? 将不相关的div添加到DOM后,为什么JQuery UI Datepicker停止工作? - Why does JQuery UI Datepicker stop working after I add an unrelated div to the DOM? 如果我使用有错误的代码,为什么我的下拉菜单停止工作? - Why does my dropdown stop working if I use code with errors? 什么时候应该在数组上使用对象,反之亦然? - When should I use an object over an array and vice versa? 将JavaScript转换为jQuery,反之亦然 - javascript to jQuery or vice versa 当我使用“==”时,为什么datepicker突出显示不起作用? - Why does datepicker highlight not work when I use “==”? 为什么当我尝试使用 props 传递的函数时 preventDefault 停止工作? - Why does preventDefault stop working when I try to use a function passed by props? codepen:当向下滚动超过锚点时,jQuery .css()编辑,反之亦然 - codepen: jQuery .css() edit when scrolldown past anchor, vice versa 播放设备音频时视频无法播放,反之亦然 - Video does not play when device audio is playing and vice versa 删除静音后,为什么我的自动播放停止工作? - Why does my autoplay stop working when I remove mute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM