zoukankan      html  css  js  c++  java
  • javascript里new构造函数返回的值

    var a = new XXX();

    a是什么?
    要分类讨论
    一:
    function XXX(){
        return 原始类型(数字,字符串,bool,null,undefined)
    }
    则a是new出来的对象

    二:
    function XXX(){
        return 引用类型
    }
    则a是这个return的值

    如:
    function XXX(){
        this.y = 10;
        return {
            x:1
        }
    }

    var a = new XXX();
    console.log(a.x); //1
    console.log(a.y); //undefined  


    再如:
    function XXX(){
        this.y = 10;
        return function aaa(){}
    }

    var a = new XXX();
    console.log(a); //aaa()
    console.log(a.x); //undefined

  • 相关阅读:
    Java多线程、并发
    Java I/O系统
    Java注解
    Arthas(Java诊断工具)
    Java泛型
    Java内部类
    libpcap使用
    python文件服务器
    设计模式
    protobuf
  • 原文地址:https://www.cnblogs.com/phper007/p/3456037.html
Copyright © 2011-2022 走看看