New Object 和Object.create()

new Object

   var a = {x:1};
//    b =new Object(a);
    var b = Object.create(a);
  console.log(b==a)//false console.log(b);//输出:{}; __proto__:Object x:1 console.log(b.x);//1 console.log(b.__proto__);//输出:{x:1} console.log(b.prototype);//undefined

 

 new Object()

    var a = {x:1};
    b =new Object(a);
//    var b = Object.create(a);
    console.log(b==a);//true
    console.log(b);//Object {x: 1}
    console.log(b.x);//1
    console.log(b.__proto__);//Object {}
    console.log(b.prototype);//undefined

  构造函数

function a(x){
        this.x=x;
    };
    b =new a(1)
//    var b = Object.create(a);
    console.log(b==a);//true
    console.log(b);//a {x: 1}
    console.log(b.x);//1
    console.log(b.__proto__);//Object {}
    console.log(b.prototype);//undefined
    console.log(b.constructor);//function a(x){this.x=x;}

  

posted on 2016-09-20 14:25  carlyin  阅读(188)  评论(0)    收藏  举报

导航