在你的ASP中使用類(class)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[p]在不入前的一天,當(dāng)我為了解決一個(gè)語法問題來翻閱vbscript文檔時(shí),偶然間發(fā)現(xiàn)在了下面的一句話:[/p]
[p]class statement[/p] [p]declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class. [/p] [p]翻譯過來就是......[/p] [p]class 聲明[/p] [p]聲明一個(gè)類的名字,就是定義一些變量,屬性,方法來組成一個(gè)類 [/p] [p]這是真的!!!?vbscript中能用類!?!?不知道能不能用于asp!?這樣的話,我就不是能寫出像object一樣的asp程序?!說干就干!實(shí)踐是檢驗(yàn)真理的唯一標(biāo)準(zhǔn),自個(gè)動(dòng)手吧![/p] [p]我們常常看到別的程序語言中中都有類的說明,php,vb,c++,這個(gè)在vbscript中的類的說明,我是第一次聽到,我們的日常工作就是網(wǎng)站開發(fā),在這個(gè)里面多多少少搞出點(diǎn)經(jīng)驗(yàn),像模像樣也能自詡為"內(nèi)行",所以我就來分享一下我所知道的這個(gè)新的東東。我們來看看下面的這個(gè)代碼吧!(window2000+iis5.0通過測(cè)試)[/p] [p]<%[br]''聲明一個(gè)名為aspcn的類 [br]class aspcn[br]private aspcn[br]''初始化類[br]private sub class_initialize[br]aspcn="aspcn is good! "[br]end sub [br]''定義一個(gè)函數(shù)[br]public function doit()[br]doit=aspcn[br]end function[br]''定義一個(gè)方法[br]public sub querystr(stat)[br]response.write stat[br]end sub [/p] [p]end class[/p] [p]set hi_aspcn=new aspcn ''定義一個(gè)名為hi_aspcn的aspcn對(duì)象實(shí)例[br]response.write hi_aspcn.doit[br]varstr="aspcn is cool! http://aspcn.com welcome!!!"[br]hi_aspcn.querystr varstr [/p] [p]%>[/p] [p][br]這是很簡(jiǎn)單的一個(gè)程序,我們?cè)谄渲新暶髁艘粋€(gè)名為aspcn的類,建立了一個(gè)doit函數(shù),一個(gè)querystr方法,這個(gè)程序很簡(jiǎn)單相信大家能看懂,它的顯示如下: [/p] [p]aspcn is good![br]aspcn is cool![br][url=http://aspcn.com]http://aspcn.com[/url][br]welcome!!! [/p] [p]以后,咱們就可以把我們常用到的程序?qū)懗梢粋€(gè)類,到時(shí)候就用<!--#include file="xxx.asp"-->來包含進(jìn)來就行了,這給我們開發(fā)程序又提供了新的空間,真是爽啊!和c++一樣了,有點(diǎn)回歸自然的感覺.[/p] 該文章在 2010/7/7 23:25:38 編輯過 |
相關(guān)文章
正在查詢... |