[英]Moment.js: “TypeError: momentRange.range” when using with moment-range
I have problem using all 3 of the packages together. 我在同时使用所有3个软件包时遇到问题。 I define them like this:
我这样定义它们:
var moment = require('moment-timezone');
var momentRange = require('moment-range');
And when I want to use the moment-range functions, I'm trying to call it like this: 当我想使用矩距函数时,我试图这样称呼它:
var range1 = momentRange.range(moment("string1"), moment("string2"));
And I'm getting error: TypeError: momentRange.range is not a function
而且我得到了错误:
TypeError: momentRange.range is not a function
What am I doing wrong? 我究竟做错了什么?
According to the documentation, you are supposed to use the moment-range
library to first extend the core moment
library itself, then use moment.range
because the moment-range
package adds additional functions to the moment
object: 根据文档,应该使用
moment-range
库首先扩展核心moment
库本身,然后使用moment.range
因为moment-range
包为moment
对象添加了其他功能:
var momentRange = require('moment-range');
momentRange.extendMoment(moment);
moment.range(moment(…), moment(…)); // Now usable
Specifically, in their documentation : 具体来说,在他们的文档中 :
CommonJS:
CommonJS的:
const Moment = require('moment'); const MomentRange = require('moment-range'); const moment = MomentRange.extendMoment(Moment);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.