JS:prototype chain

来源:互联网 发布:计算机维护与网络管理 编辑:程序博客网 时间:2024/06/18 14:59

The "prototype chain" in JavaScript knows this as well. If JavaScript encounters something it can't find in the current class's methods or properties, it looks up the prototype chain to see if it's defined in a class that it inherits from. This keeps going upwards until it stops all the way at the top: the mighty Object.prototype(more on this later). By default, all classes inherit directly from Object, unless we change the class'sprototype, like we've been doing forPenguin and Emperor.

Briefly,We say:

 we can define a method for a class, and any instance of the class (i.e., object created using that class's constructor) can use that method.

Tips:Remember that classes and the prototype are important to OOP!

0 0