zoukankan      html  css  js  c++  java
  • 关于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 说明是原生代码 底层写该函数的代码 

    其他基本类型一样

  • 相关阅读:
    C++ Websites
    C++ smart pointer
    Use of ‘const’ in Functions Return Values
    Meaning of “const” last in a C++ method declaration?
    为什么不要使用"using namespace XXX"
    android.os.Handler
    Windows下Anaconda的安装和简单使用
    matlab GPU 操作
    matlab 在柱状图上 显示数字
    How to fix apt-get GPG error NO_PUBKEY Ubuntu 14
  • 原文地址:https://www.cnblogs.com/HKUI/p/3352924.html
Copyright © 2011-2022 走看看