JS的 Prototype
这几天一直在接触Aris,Aris的报表语法是JavaScript,报表中有很多面向对象的思想,所以一一记录下来,应对大脑内存泄漏,大脑硬盘区域损坏或者大脑重启等状况!
这篇文章主要是记录 JS Prototype
javascript的方法可以分为三类:
a 类方法
b 对象方法
c 原型方法
例子:
function People(name) { this.name=name; //对象方法 this.Introduce=function(){ alert("My name is "+this.name); } } //类方法 People.Run=function(){ alert("I can run"); } //原型方法 People.prototype.IntroduceChinese=function(){ alert("我的名字是"+this.name); } //测试 var p1=new People("Windking"); p1.Introduce(); People.Run(); p1.IntroduceChinese();
Prototype 简单应用
var _m = function(){ this.a = ""; this.b = ""; this.c = ""; _m.prototype.load = function(){ this.a = "a"; this.b = "b"; this.c = "c"; } _m.prototype.reset = function(m){ this.a = "a"+m; this.b = "b"+m; this.c = "c"+m; } _m.prototype.save = function(m,n){ this.a = "save-a"+m+n; this.b = "save-b"+m+n; this.c = "save-c"+m+n; } } var mm = new _m(); //mm.load(); //mm.reset('1'); mm.save('bcdefg','highlmn'); alert(mm.a); alert(mm.b); alert(mm.c);
参考文章
[http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html]
浙公网安备 33010602011771号