介绍
作者:http://www.aspcn.com 飞刀
在不入前的一天,当我为了解决一个语法问题来翻阅vbscript文档时,偶然间发现在了下面的一句话:
class statement
declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.
翻译过来就是……
class 声明
声明一个类的名字,就是定义一些变量,属性,方法来组成一个类
这是真的!!!?vbscript中能用类!?!?不知道能不能用于asp!?这样的话,我就不是能写出像object一样的asp程序?!说干就干!实践是检验真理的唯一标准,自个动手吧!
我们常常看到别的程序语言中中都有类的说明,php,vb,c++,这个在vbscript中的类的说明,我是第一次听到,我们的日常工作就是网站开发,在这个里面多多少少搞出点经验,像模像样也能自诩为"内行",所以我就来分享一下我所知道的这个新的东东。我们来看看下面的这个代码吧!(window2000+iis5.0通过测试)
<%
声明一个名为aspcn的类
class aspcn
private aspcn
初始化类
private sub class_initialize
aspcn="aspcn is good!<br>"
end sub
定义一个函数
public function doit()
doit=aspcn
end function
定义一个方法
public sub querystr(stat)
response.write stat
end sub
end class
set hi_aspcn=new aspcn 定义一个名为hi_aspcn的aspcn对象实例
response.write hi_aspcn.doit
varstr="aspcn is cool!<br><font color=red>http://www.aspcn.com</font><br>welcome!!!"
hi_aspcn.querystr varstr
%>
这是很简单的一个程序,我们在其中声明了一个名为aspcn的类,建立了一个doit函数,一个querystr方法,这个程序很简单相信大家能看懂,它的显示如下:
aspcn is good!
aspcn is cool!
http://www.aspcn.com
welcome!!!
以后,咱们就可以把我们常用到的程序写成一个类,到时候就用<!–#include file="xxx.asp"–>来包含进来就行了,这给我们开发程序又提供了新的空间,真是爽啊!和c++一样了,有点回归自然的感觉.
本文章来自于http://www.aspcn.com asp中华网如要转载请务必注明出处,谢谢
