constructor 是创建对象实例所引用的构造器,prototype是对象实例所共享的属性和方法的集合
有点像java中的static 声明的函数和属性
<script type="text/javascript">
function MyObj(id,name){
    this.id=id;
    this.name=name;
}
MyObj.prototype.show=function(){
    alert(this.id);
}
MyObj.prototype.className="MyObj";var obj1=new MyObj(1,"obj1");
var obj2=new MyObj(2,"obj2");alert(obj1.constructor);
alert(obj1.constructor==obj2.constructor);
alert(obj1.className);
alert(obj2.className);
alert(obj1.constructor.prototype.className);
</script>

解决方案 »

  1.   

    随便说说
    先说:constructor
    constructor是对新对象所被创建对象的描述。通俗一点就是:用来解释此对象是由什么对象创建的.
    比方说:function newFun(){}
    var dt=new Date();
    var str=new String();
    var nfun = new newFun();
    alert(dt.constructor);//显示Date
    alert(str.constructor);//显示String
    alert(nfun.constructor);//显示newFun此方法主要用来验证 新方法 或新对象的原始对象是什么.有点类似于typeof再说:prototype
    prototype 是对象类型原型的引用 ,看看他的英文主成:proto-type 嘿嘿就是主要类型的意思;
    都知道如果对于java此类的语言,String 类已经是final类了,没办法扩展他的属性和方法.但是js就不一样拉.
    他可以对类型进行属性和方法的扩展
    比如说:
    这里有我两个方法://删除数组中指定位置的项并返回新书组
    Array.prototype.remove = remove;
    function remove(num){
    var numc=parseInt(num);
    if(numc<0||numc>this.length){return;}
    var new1=this.slice(0,numc) 
    var new2=this.slice(numc+1,this.length) 
    return new1.concat(new2)
    }
    var ss=[];
    ss.push(1)
    ss.push(2)
    ss.push(3)
    ss.push(4)
    ss.push(5)
    var dd=ss.remove(2)
    var innr="";
    for(var a=0;a<dd.length;a++){
    innr+=dd[a]
    }
    alert(innr)//获取字符串中指定位置的字符
    String.prototype.getIndexof=getidof;
    function getidof(i){
    var ii=parseInt(i)
    if(ii<0 || ii>this.length){return "";}
    return this.substr(i-1,i);
    }var ss="123456";
    alert(ss.getIndexof(2))//新的obj
    function Zobj(){this.title="新的obj";}
    Zobj.prototype.getTitle= function(){
    return this.title;
    }var obj= new Zobj();
    alert(obj.getTitle())
    prototype 方法主要是用来扩展或重写已有对象的内置方法或属性
    你如果新建一个对象也可以这样扩展它的属性和内置方法