• 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"
  • 相关阅读:
    JavaWeb
    List的三种遍历(转)
    Java中父类和子类集合互相转换(转)
    Day4
    Ubuntu20.04配置 ES7.17.0集群
    K8S中部署apisix(非ingress)
    使用 Flutter&&Hive&&Bloc 写一个待办小demo
    SQL多行数据分组后合并某个字段
    sql group 拼接字段
    Socket
  • 原文地址:https://www.cnblogs.com/yjstonestar/p/4245655.html
Copyright © 2020-2023  润新知