• typeofconstructor 简单


    1. typeof 

      返回值: string number boolean function object undefined

    其中通过typeof null 返回:object 

    2. constructor

      返回值:String Boolean Number Array  Date Function  Object ...

    看示例:

    //constructor

    function test3() {

        var s = "123";

        var n = 1000.111;

        var f = true;

        var arr = [1, 2, 3];

        var json = {1: "123", obj: "number"};

        var fun = new Function();

        var fun2 = function() {return test1};

        var date = new Date();

        var obj = new Dog();

         function Dog() {

            this.dog = "dog";

        }

    //    alert([].constructor);

    //    console.log(null.constructor, undefined.constructor);     //报错 null和undefined不存在property

    // 备注: 很有趣的现象:

    //数值直接量没有constructor属性,不过通过括号运算符就能解决:

    //如: (10).constructor 

        console.log(f.constructor, f.constructor === Boolean);

        console.log(s.constructor, s.constructor === String, n.constructor, n.constructor === Number);

        //ff的console出现bug

        // [].constructor === Array

        console.log(arr.constructor, [].constructor, "array", Array.constructor, new Array().constructor, "json", json.constructor);

        console.log("fun", fun.constructor, "func2", fun2.constructor);

        console.log("date", date.constructor, "obj", obj.constructor);

        console.log(Object.constructor === Function,  Function.constructor === Function)

    }

    test3();

  • 相关阅读:
    Nginx 的 Location 配置指令块
    linux java环境配置
    WebUploader API文档
    cron表达式详解
    Android中设置自己软件的铃声+震动
    java格式化输出 printf 例子
    Android_Intent意图详解
    MyEclipse Could not create the view: An unexpected exception was thrown解决方案
    HttpClient技术
    java-Object类中的方法
  • 原文地址:https://www.cnblogs.com/chyong168/p/2256203.html
Copyright © 2020-2023  润新知