js call 用法

		<script type="text/javascript">
			function car() {
			   name='n';	
			   color='c';
			   doors='d';
			}

			function show() {
				alert(name +"-"+ color +"-"+ doors )
			}
			
			//var c1=new car("bmw", 'red', 2);

			show.call(car());
		</script>

 

 

执行把car放在show中执行show

 

 

function Animal(name){      
    this.name = name+100;      
    this.showName = function(){      
        alert(this.name);      
    }      
}      
    
function Cat(name){    
	this.name=name+10000;
    Animal.call(this, name);    
}      
    
var cat = new Cat(2); 
 alert(cat.name)  

结果:102

复写

  

你可能感兴趣的:(call)