关于JS  Object中类、类私有方法、类公有方法、原形方法的问题测试。


 <HEAD>
  
<TITLE> New Document </TITLE>
  
<META NAME="Generator" CONTENT="EditPlus">
  
<META NAME="Author" CONTENT="">
  
<META NAME="Keywords" CONTENT="">
  
<META NAME="Description" CONTENT="">
  
<script>
    
function Passenger()
    {
        Name 
= function()
        {
            alert(
"zh");
            
return "adam";
        }

        
this.Person = function()
        {
            
var str = "";
            str 
+= Name();
            alert(str);
            
return str;
        }

        
var imgshow = document.getElementById("imgShow");
        
//alert(imgshow);
        imgshow.src = "http://img1.pconline.com.cn/pconline/0707/30/1068776_070731_cool_ip_05.jpg";
        imgshow.style.display 
= "none";
    }

    
function MyClass()
    {
        
this.Name = "Hello";
    }

    MyClass.prototype.MyFun 
= function()
    {
        alert(
this.Name);
    }

    
function Animal(name)
    {
        
this.name = name;
        alert(
this.name);
    }

    
function Dog(name)
    {
        Animal.call(
this, name);
    }

    Dog.prototype 
= new Animal();

    Dog.prototype.ChangeName 
= function(newName)
    {
        
this.name = newName;
        alert(
this.name);
    }
  
</script>
 
</HEAD>

 
<BODY>
  
<img id="imgShow" src="" />
  sfdsfdafdsa
  
<script>

      
//var passenger = new Passenger();
    //passenger.Person();
    
    
var animal = new Animal("tony");
    
var dog = new Animal("Jerry");
    
var subDog = new Dog("Leny");
    subDog.ChangeName(
"Andy");
  
</script>
 
</BODY>
</HTML>

相关文章:

  • 2021-08-29
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2022-01-05
  • 2021-08-05
  • 2021-11-20
相关资源
相似解决方案