prototype笔记

function a(name,age){
        this.name = name;
        this.age = age;
    }
    console.log(a.prototype)
//Object
    1. constructor:a(name,age)
    2. __proto__:Object

prototype:1、function带有的默认属性

                 2、是一个对象,是这个函数的属性的集合

                 3、包含一个constructor和_proto_

//怎么实现继承
 function a(name,age){
        this.name = name;
        this.age = age;
    }
 function b(){};
console.log( b.prototype)//
//Object
//constructor: b()__
//proto__: Object

//实现继承
 b.prototype = new a();
 console.log( b.prototype)//a {name: undefined, age: 1},a也是函数对象,通过new Function
因为每个对象(实例化)都有_proto_指向改对象构造函数的原型,从而继承了a的属性

 

posted @ 2017-03-09 15:45  黄先森  阅读(149)  评论(0编辑  收藏  举报