zoukankan      html  css  js  c++  java
  • ExtJs--09--javascript对象的方法的3种写法 prototype通过原型设置方法效率最好

    	/**
    	 * 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());

  • 相关阅读:
    申请奖励加分
    寒假学习01
    加分项及建议
    12月30日总结
    12月17日 期末总结
    12月31日总结
    12月15日总结
    12月28日总结
    01月03日总结
    01月05日总结
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6865661.html
Copyright © 2011-2022 走看看