Web front-end Interview Guide (27): What is the prototype? What is the prototype chain?

Source: Internet
Author: User
Tags inheritance

Topic comments

This topic belongs to JavaScript more difficult to understand the knowledge point, the knowledge is also very abstract abstruse, belong to the JavaScript object-oriented thinking category, if there is no object-oriented programming thinking students, must be stumped, even if there is some OOP students to answer it is also more laborious , not 1:30 will be able to speak clearly. But the interviewer asked, stating that he is skilled, in a more professional terms to answer the good, this will be more concise. ideas for solving problems what the prototype is.

In JavaScript, a prototype is a prototype object that represents the relationship between types. What the prototype chain is.

JavaScript is the object of all things, objects and objects are also related, and not isolated. An inheritance relationship between objects, in JavaScript by prototype objects to the parent object, until the object is pointed, so that a prototype is pointed to the chain, and the jargon is called the prototype chain. Give an example to explain

Student→person→object, the student inherits the human, the human inherits the object class

Code

<span style= "FONT-SIZE:14PX;" >varperson=function () {this.age= "anonymous"};
Varstudent=function () {};
Creates an inheritance relationship, prototype an instance object student.prototype=new person  ();</span>

Prototype API diagram

Thin map



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.