A misunderstanding of call and apply

Source: Internet
Author: User

<!doctype html> forInherit </title> functionBasea ()//Base Class A   {     This. Member = "Basea Member";  This. Showselfa =function() {Window.alert ( This. Member); }   }   functionBaseb ()//Base Class B   {     This. Member = "BASEB Member";  This. SHOWSELFB =function() {Window.alert ( This. Member); }   }   functionExtendab ()//Inherit Class from A and B{Basea.call ( This);//Call for ABaseb.call ( This);//Call for B} window.onload=function()   {    varExtend =NewExtendab ();  Extend.showselfa (); //Show AEXTEND.SHOWSELFB ();//Show B   }  </script> </body>

The results of the operation are as follows:

BASEB Member
BASEB Member

Test environment: Google Chrome

Results Analysis:

The expected result should be output BASEA member and BASEB member, but the actual output is BASEB member and BASEB member

In this way to achieve so-called multi-inheritance, the result: the same variable will be overwritten;

Of course, we can also make a slight modification to the above Basea code to verify the correctness of our debug analysis:

function Basea ()  //  base Class Athis. Membera = "Basea Member";   // member changed to Membera to distinguish member in Baseb  This function () {  Window.alert (this. membera);    // Show Membera  }}

A misunderstanding of call and apply

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.