小编KMS*_*KMS的帖子

Javascript调用Child中的父构造函数(prototypical inheritance) - 它是如何工作的?

我知道它有效,但我不知道为什么以及如何.有什么机制?

// Parent constructor
function Parent(name){
  this.name = name || "The name property is empty";
}

// Child constructor
function Child(name){
  this.name = name;
}

// Originaly, the Child "inherit" everything from the Parent, also the name property, but in this case
// I shadowing that with the name property in the Child constructor.
Child.prototype = new Parent();

// I want to this: if I dont set a name, please inherit "The name property is empty" from the 
// Parent …
Run Code Online (Sandbox Code Playgroud)

javascript constructor prototype call chain

11
推荐指数
1
解决办法
7105
查看次数

标签 统计

call ×1

chain ×1

constructor ×1

javascript ×1

prototype ×1