简体   繁体   English

typeof(/ \\ s /)和$ .type(/ \\ s /)之间的区别

[英]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" 如果将typeofobject一起使用,则会得到"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"

Documentation on $.type $ .type上的文档

暂无
暂无

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

相关问题 (typeof variable ===&#39;boolean&#39;)和(typeof variable ==&#39;boolean&#39;)之间有什么区别? - What's the difference between (typeof variable === 'boolean') and (typeof variable == 'boolean')? JavaScript中的“ typeof str”和“ typeof(str)”有什么区别? - What's the difference between “typeof str” and “typeof(str)” in JavaScript? (typeof variable ===“function”)和jQuery.isFunction()之间有什么区别? - What's the difference between (typeof variable === “function”) and jQuery.isFunction()? typeof === 和 typeof == 的区别 - Difference between typeof === and typeof == typeof foo和typeof(foo)/ delete bar和delete(bar)有什么区别,为什么我们都需要? - What's the difference between typeof foo and typeof(foo) / delete bar and delete(bar), and why do we need both? 在做回退时,window.jQuery和if(typeof jQuery ==“undefined”)之间有什么区别? - What's the difference between window.jQuery and if (typeof jQuery == “undefined”) when doing fallback? &#39;$(this)&#39;和&#39;this&#39;有什么区别? - What's the difference between '$(this)' and 'this'? (|)和(||)之间有什么区别? - What's the difference between ( | ) and ( || )? `2 == {}`和`{} == 2`之间有什么区别? - What's difference between `2 == {}` and `{} == 2` Object.prototype.toString.call 和 typeof 有什么不同 - what's different between Object.prototype.toString.call and typeof
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM