[英]Difference between typeof(/\s/) and $.type(/\s/)
I don't understand why it's throwing message object
when I try: 我不明白为什么在尝试时会抛出消息
object
:
alert(typeof(/\\s/))
To check again, I've made a change: 为了再次检查,我进行了更改:
alert($.type(/\\s/))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
We've got regexp
now. 我们现在有正则
regexp
。
So, my question: why is typeof(/\\s/)
an object
instead of string
or regexp
in javascript? 所以,我的问题是:为什么
typeof(/\\s/)
是object
而不是JavaScript中的string
或正则regexp
?
A regular expression is an "object" because it's an object, just like Date, etc. A regular expression is an object that describes a pattern of characters. 正则表达式是一个“对象”,因为它是一个对象,就像日期等。正则表达式是一个描述字符模式的对象。
If you use typeof
with an object
, you get "object"
如果将
typeof
与object
一起使用,则会得到"object"
Some other examples: 其他一些例子:
typeof []; // "object"
typeof null; // "object"
typeof /regex/ // "object"
typeof new String(""); // "object"
With $.type
使用
$.type
If the argument is either a primitive value or an instance of a standard built-in ECMAScript object, the [[Class]]
internal property is used to determine the type. 如果参数是原始值或标准内置ECMAScript对象的实例,则
[[Class]]
内部属性用于确定类型。
Example: 例:
jQuery.type( /test/ ) === "regexp"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.