Discuss / JavaScript / arr ----> Array.prototype ----> Object.prototype ----> null 这个原型链箭头我现在弄明白了,但是对于不是用new 函数这种方式构建的对象呢?

arr ----> Array.prototype ----> Object.prototype ----> null 这个原型链箭头我现在弄明白了,但是对于不是用new 函数这种方式构建的对象呢?

Topic source

王奋浩2015

#1 Created at ... [Delete] [Delete and Lock User]

如果a = new b() 那a的原型就是函数b的原型,那如果 用a=Object.create(c)这种方式创建的a的原型就是c是吗?就是说两种方式创建的对象的原型链的结构是有区别的是吗?

colorsumer

#2 Created at ... [Delete] [Delete and Lock User]

是啊。廖老师讲的很明白

function b(){}; function c(){};

var a=new b(); alert(a.proto===b.prototype);//true

a=Object.create(c); alert(a.proto===c);//true

有疑问试一下,就清楚了。

可以大致类比为:使用a = Object.create(c);类比为继承, 使用a = new(c);类比为直接创建对象, 继承过来的当然原型是父类,直接创建的当然原型和原来的类的原型是一样的。 虽然很不严谨,但是大概是这么理解吧。


  • 1

Reply