javascript prototype笔记(其一)

<script>
 
 function _BASE(){
	
	this.showMsg=function(){
		alert("_BASE::showMsg");
	}
	
 }
 
 _BASE.toast=function(){
	alert("_BASE::::toast");
 }
 
 _BASE.prototype.show=function(){
	alert("_BASE::prototype::show");
 }
 
 //调用类方法
 _BASE.toast()

var base=new _BASE();
//调用对象方法
base.showMsg(); 
 
 //调用原型方法
base.show();
 
 
 </script>


带参数的调用

<script>
 
 function _BASE(name){
	this.name=name;
	this.showMsg=function(){
		alert("_BASE::showMsg::"+this.name);
	}
	
 }
 
 _BASE.toast=function(name){
	alert("_BASE::toast::"+name);
 }
 
 _BASE.prototype.show=function(){
	alert("_BASE::prototype::show::"+this.name);
 }
 
 //调用类方法
 _BASE.toast("Fred")

var base=new _BASE("Fred");
//调用对象方法
base.showMsg(); 
 
 //调用原型方法
base.show();
 
 
 </script>



你可能感兴趣的:(JavaScript,prototype,Fred)