zoukankan      html  css  js  c++  java
  • JQuery type

    jQuery.extend({
        type: function( obj ) {
            if ( obj == null ) {
                return String( obj );
            }
            // Support: Safari <= 5.1 (functionish RegExp)
            return typeof obj === "object" || typeof obj === "function" ?
                class2type[ core_toString.call(obj) ] || "object" :
                typeof obj;
        }
    });

    其中typeof的返回值有:

    typeof是一个一元运算符,它返回的结果 始终是一个字符串,对不同的操作数,它返回不同的结果。
    具体的规则如下:
    一、对于数字类型的操作数而言, typeof 返回的值是 number。

    二、对于字符串类型, typeof 返回的值是 string。比如typeof("123")返回的值是string。 
    三、对于布尔类型, typeof 返回的值是 boolean 。比如typeof(true)返回的值是boolean。
    四、对于对象、数组、null 返回的值是 object 。比如typeof(window),typeof(document),typeof(null)返回的值都是object。
    五、 对于函数类型,返回的值是 function。比如:typeof(eval),typeof(Date)返回的值都是function。
    六、如 果运算数是没有定义的(比如说不存在的变量、函数或者undefined),将返回undefined。比如:typeof(sss)、typeof(undefined)都返回undefined。

    关于typeof 请参考:http://www.cnblogs.com/yjstonestar/p/4245638.html

    以下是与jQuery.type()函数相关的jQuery示例代码,以演示jQuery.type()函数的具体用法:

    jQuery.type( undefined ); // "undefined"
    jQuery.type( null ); // "null"
    
    jQuery.type( true ); // "boolean"
    jQuery.type( new Boolean(true) ); // "boolean"
    
    jQuery.type( 3 ); // "number"
    jQuery.type( new Number(3) ); // "number"
    
    jQuery.type( "test" ); // "string"
    jQuery.type( new String("test") ); // "string"
    
    jQuery.type( function(){} ); // "function"
    jQuery.type( new Function() ); // "function"
    
    jQuery.type( [] ); // "array"
    jQuery.type( new Array() ); // "array"
    
    jQuery.type( new Date() ); // "date"
    
    jQuery.type( new Error() ); // "error" // jQuery 1.9 新增支持
    
    jQuery.type( /test/ ); // "regexp"
    jQuery.type( new RegExp("\d+") ); // "regexp"
    
    /* 除上述类型的对象外,其他对象一律返回"object" */
    
    jQuery.type( {} ); // "object"
    function User() { }
    jQuery.type( new User() ); // "object"
  • 相关阅读:
    基金相关知识整理
    Apache Shiro反序列化漏洞复现
    payload分离免杀
    Red Team 工具集之网络钓鱼和水坑攻击
    GPP(Group Policy Preference)组策略偏好漏洞利用
    AdFind
    python爬虫之beautifulsoup的使用
    xargs命令_Linux xargs命令:一个给其他命令传递参数的过滤器
    mutillidae之注册页面的Insert型报错注入
    mutillidae之Insert型注入
  • 原文地址:https://www.cnblogs.com/yjstonestar/p/4245655.html
Copyright © 2011-2022 走看看