javascript的方法可以分为三类:
a 类方法
b 对象方法
c 原型方法
var Demo=function(name){ this.name=name; this.show1=function(){ alert("this is 对象方法"); } } Demo.show2=function(){ alert("这是一个类方法"); } Demo.propertype.show3=function(){ alert("这是一个原型方法"); }
调用:
var demo = new Demo(); demo.show1(); Demo.show2(); demo .show3();
一、原型propertype
javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用。
通过propertype声明的方法,如
var checkObject = function(){}; checkObject.propertype.checkName=function(){ //验证姓名 } checkObject.propertype.checkPassword=function(){ //验证密码 }
在创建对象实例的时候,创建出来的对象所拥有的方法是一个。