我从函数中得到的返回值始终是字符串。我使用了typeof(obj)
,结果总是string
。
Date.functionName=Date.prototype.functionName=function(dataObj) {
//The dataObj is always string.
// How can i differentiate between the values...
};
我有三件事作为字符串..
- 日期
- 字符串...
- 整数值...
这三个都是字符串
类型。
- 如何区分这三个值。
- 使用 Date.mycustomfunction 是否正确...或者我应该使用一些 其他类(class)...
最佳答案
您可以使用isNaN检查它是否是整数。还有一些有趣的想法here对于 isDate 类型的功能。这里的一些答案可能会有所帮助:How can I determine whether a given string represents a date?
关于javascript - 确定返回值的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6807645/