欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ExtJs--09--javascript对象的方法的3种写法 prototype通过原型设置方法效率最好

程序员文章站 2022-08-10 15:31:09
/** * javascript对象的方法的3种写法 推荐第三种 执行效率最好 */ function P(name , age){ this.name = na...
	/**
	 * javascript对象的方法的3种写法  推荐第三种 执行效率最好
	 */
	function P(name , age){
		this.name = name ; 
		this.age = age ;
		//第一种方法
		this.show = function(){
			alert(this.name);
		}
		this.doing = doing ; 
	}
	//第二种方法
	function doing(){
		alert(this.name);
	}
	//第三种方法
	//javascript中 prototype 原型  被所有类的实例对象共享
	P.prototype.dd = function(){
		alert(this.name);
	}
	
	var p1 = new P("mary",22);
//	Ext.Msg.alert("提示标题","提示信息")
	var p2 = new P("rose" , 25);
//	alert(p1.show()==p2.show());
	
//	alert(p1.doing()==p2.doing());
	
	alert(p1.dd()==p2.dd());