• 关于js一般对象与标配对象


     

    当一个js函数对象被创建时,Function 构造器产生的函数对象会运行类似这样的一些代码

    this.prototype={constructor:this}

    新函数被赋予了一个prototype属性,它的值是一个对象,该对象包含了一个constructor属性,该属性的值为改新函数的对象

    
    
    function fun(){
        alert('world');
    }
    alert(fun.prototype.constructor==fun);//true
    alert(fun.__proto__==Function.prototype)//true
    alert(fun.prototype.constructor);//即为该函数对象
    alert(toString.prototype.constructor);//系统自带函数,返回native code
    
    

      

    构造函数类(首字母大写)
    function Car(color){
        this.color=color;
        this.age=100;
    }
    Car.prototype.color="blue";
    Car.prototype.showColor=function(){
        alert(this.color);
    }
    alert(Car.prototype.constructor);  //打印出构造函数体即函数本身对象
    var car1=new Car('red');
    alert(car1.__proto__==Car.prototype);//true 原型链
    alert(car1.constructor);//构造函数
    alert(car1.prototype);//undefined
    alert(typeof car1);//obj
     

    String 对象与字符

    所有字符默认都连接到String.prototype对象上

    无论是否是用new String() 创建的

    var str=new String('ab');
    
    var str1="abc";
    
    alert(typeof str); //obj obj 
    
    alert(typeof str1); //string
    
    alert(str.__proto__==String.prototype);//true
    
    alert(str1.__proto__==String.prototype);//true
    
    alert(str.constructor);//native code 说明是原生代码 底层写该函数的代码 

    其他基本类型一样

  • 相关阅读:
    Pycharm 中的翻译工具
    服务器响应慢问题
    将博客搬至CSDN
    【索引】索引的介绍与优化
    【Java杂记】Equals 和 hashCode
    【Java】JVM(六)虚拟机字节码执行引擎
    【Java】JVM(五)、虚拟机类加载机制
    【Java】JVM(四)、虚拟机参数配置
    【Java】JVM(三)、Java垃圾收集器
    【Java】JVM(二)、Java垃圾收集算法
  • 原文地址:https://www.cnblogs.com/HKUI/p/3352924.html
Copyright © 2020-2023  润新知