// _proto_ 在函数里有一个属性prototype 由该函数创建的对象默认会连接到该属性上 //prototype 与 _proto_ 的关系 _proto_是站在对象角度来说的 prototype 是站在构造函数角度来说的下面,我们来看图说话。

了解这些之后,我们再来讨论什么是原型链。说白了,其实就是有限的实例对象和原型之间组成有限链,就是用来实现共享属性和继承的。下面,我们看代码说话。
var obj = new Object();对象是有原型对象的原型对象也有原型对象 obj._proto_._proto_._proto_原型对象也有原型对象,对象的原型对象一直往上找,会找到一个null// 原型链示例var arr = [];arr -> Array.prototype ->Object.prototype -> nullvar o = new Object();o -> Object.prototype -> null;function Foo1(){this.name1 = "1";}function Foo2(){this.name2 = "2";}Foo2.prototype = new Foo1();function Foo3(){this.name = "3";}Foo3.prototype = new Foo2();var foo3 = new Foo3();console.dir(foo3);

接下来就是继承问题了。
2、继承
1)原型继承
function Animal(name){this.name = name;}function Tiger(color){this.color = color;}//var tiger = new Tiger("yellow");//console.log(tiger.color);//console.log(tiger.name); //undefined// Tiger.prototype = new Animal("老虎");//一种方式Object.prototype.name = "大老虎";//第二种方式var tiger = new Tiger("yellow");console.log(tiger.color);console.log(tiger.name);值得注意的是,这里存在两个主要的问题:①它不方便给父级类型传递参数;②父级类型当中的引用类型被所有的实例共享————做兼容 //shim垫片function create(obj){if(Object.create){return Object.create(obj);}else{function Foo(){}Foo.prototype = obj;return new Foo();}} 这种方法是ES5的新特性,其实就是复制继承。var obj = {}; obj.extend = function(obj){ for(var k in obj){this[k] = obj[k]; } } 4)借用构造函数继承——被借用的构造函数中原型上的成员没有被借过来function Animal(name){this.name = name;}function Mouse(nickname){Animal.call(this,"老鼠");this.nickname = nickname;}var m = new Mouse("杰瑞");console.log(m.name);console.log(m.nickname); 存在的问题:可以解决原型继承当中传参问题,但是父类型当中的原型对象上的成员(属性和方法)不能被继承到function Person(name){this.name = name;}Person.prototype.showName = function(){console.log(this.name);}function Student(name,age){Person.call(this,name);this.age = age;}Student.prototype = new Person();Student.prototype.contructor = Student;Student.prototype.showAge = function(){console.log(this.age);}var stu = new Student("张三",12);stu.showName();stu.showAge();【原型继承+借用构造函数继承】它的特点就是属性每个实例一份,方法共享