JavaScript Prototype Memo

Source: Internet
Author: User

__PROTO__: Properties for all objects.

 var obj =//{}varnew//{}var  function//[Function:empty]

Prototype: A property in a function object.

var obj = {}; var function () {};console.log (func.prototype);   // {}//undefined

The root of all objects is Object,object __proto__ is null

var obj =//{}//nullvarfunction  // [Function:empty] // {}Console.log (func.__proto__.__proto__.__proto__); // NULL

An object that is __proto__ to the prototype of the constructor by using the constructor to create the object

var function  = ' F1 '//{name: ' F1 '}varnew//{name: ' F1 '}//true

When implementing inheritance, __proto__ points to: Dog1 Instance->dog.prototype->animal.prototype->object->null

functionAnimal () {}animal.prototype.name= ' Animal ';functionDog () {}dog.prototype=NewAnimal ();D og.prototype.height= 10;
Console.log (Animal.prototype); {Name: ' Animal '}
Console.log (Dog.prototype); {Height:10}varDog1 =NewDog (); Console.log (DOG1);//{}Console.log (dog1.__proto__);//{height:10}Console.log (dog1.__proto__.__proto__);//{name: ' Animal '}Console.log (dog1.__proto__.__proto__.__proto__);//{} objectConsole.log (dog1.__proto__.__proto__.__proto__.__proto__);//NULL root
Console.log (Dog1.name); Animal
Console.log (Dog1.height); 10

Well, just learning JavaScript, I think about that so much for a moment.

  

JavaScript Prototype Memo

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.