我的应用程序有一个 HTML 表单,其中一些输入由后端填充,其他输入由用户输入(在 time
输入中)。当用户更改值时,onChange
函数将遍历每个输入。
后端填充的输入被转换成 moment
对象,用户输入的日期只是字符串。这意味着 onChange
函数遇到一些 moment
对象和一些字符串。我需要知道哪些输入是 moment
对象,哪些不是。
测试变量是否是 moment
对象的推荐方法是什么?
我已经注意到 moment
对象具有 _isAMomentObject
属性,但是我想知道是否还有其他方法来测试变量是否是 moment
对象。
我尝试的另一个选项是对变量调用 moment
。这会将 string
变量转换为 moment
对象,而且似乎不会影响现有的 moment
对象。