日期:2014-05-16  浏览次数:20870 次

asp如何实现像类接口的功能
我想实现像类的接口功能。

<%
class dataGrid
  public function selector()
  end function

  function Init()
      dim result:result = selector
      response.write(result)
  end function  
end class
%>

dim table
set table = new dataGrid
    '我想这里能像JS那样把实现方法替换掉 table.selector = function(){这里编写新的方法}
    table.selector = ?-- 在asp中这里应该怎样编写呢--?
    table.Init()
set table nothing

类,接口,asp

------解决方案--------------------
不能够这么写.....
------解决方案--------------------
<script language='vbs'>
class delegate
 dim arr()
 dim arrTrue
 Private Sub Class_Initialize   
  arrTrue=false
 End Sub

 function add(funname,obj)
  if arrTrue=true then
   redim Preserve arr(ubound(arr)+1,1)
  else
   arrTrue=true
   redim Preserve arr(0,1)
  end if
  set arr(ubound(arr),0)=obj
  arr(ubound(arr),1)=funname
 End function

 Sub exec
  for i=0 to ubound(arr)
   execute "arr(" & i & ",0)." & arr(i,1)
  next
 End Sub
end class

class client
dim d 
Private Sub Class_Initialize 
set d= new delegate
end sub
public property set selector(p)
set d=p
end property
public property get selector
set selector=d
end property
end class

class test
sub test
alert 1
end sub

sub test1
alert 2
end sub
end class



set c = new client

set t = new test

c.selector.add "test", t
c.selector.exec

set c.selector= new delegate
c.selector.add "test1", t
c.selector.exec
</script>

client 类相当于你的调用类,可以随时转换调用其他的类
------解决方案--------------------
委托类是
https://www.google.com.hk/search?q=vbs+%E5%A7%94%E6%89%98&oq=vbs+%E5%A7%94%E6%89%98&aqs=chrome..69i57j0l5.6840j0&sourceid=chrome&espvd=210&es_sm=93&ie=UTF-8

的第一篇文章 

------解决方案--------------------
通过函数argument的个数不同 可以实现函数的重载
------解决方案--------------------
ASP还是老老实实用过程吧。
------解决方案--------------------
getref
------解决方案--------------------
execute eval等等后期绑定的方式都是解决方案