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();
{
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();
JavaScript方法分类与实例应用
本文详细介绍了JavaScript方法的三类分类:a类方法、b对象方法和c原型方法,并通过实例展示了如何在实际编程中使用这些方法。

591

被折叠的 条评论
为什么被折叠?



