SoFunction
Updated on 2025-02-28

JavaScript prototype prototype operation notes


//var People={name:"xiong",age:15};
//var Person=function(user,age){
//    =user;
//    =age;
//    =function(){alert("I am "++"\n"+);}
//}
//var Chairman=function(name,salary){
//    (this,name);
//    }
//var Bill=new Person("Bill",15);
//var Hu=new Chairman("Hu Jintao");
//=function(){
//    alert("I'm eating");
//    }
//();
function Person(name) //Basic class constructor
{
= name;
};

= function() //Add method to the prototype of the base class constructor
{
alert("Hello, I'm " + );
};

function Employee(name, salary) //Subclass constructor
{
(this, name); //Calling the base class constructor
= salary;
};

    function Xiong(name,age){
        (this,name);

        }

= new Person(); //Build a base class object as a prototype of the subclass prototype, which is very interesting here

    =new Employee();

= function() //Add method to the prototype of the subclass constructor
{
alert( + " $" + );
};
var BillGates = new Person("Bill Gates"); //Create the BillGates object of the base class Person
var SteveJobs = new Employee("Steve Jobs", 1234); //Create the SteveJobs object of the subclass Employee
var hiakuotiankong=new Xiong("The sea is wide and the sky");
var benbenxiong=new Xiong("Silly Bear");

// (); // Directly call the prototype method through the object
// (); // Directly call the base class prototype method through the subclass object, follow!
=function(){ //The SayHello method that covers the prototype
         alert("haha,I'm"+);
}
         ();
// (); // Directly call the subclass prototype method through the subclass object
// alert( == ); // Show: true, indicating that the prototype method is shared
    =function(){
         alert(+"Bye-bye");
        }
    ();