博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ColdFusion中的继承

Posted on 2004-08-16 22:21  dalongzero  阅读(1149)  评论(2)    收藏  举报
ColdFusion中的继承体现在CFCs,用法就是在<cfcomponent>中加入属性extends,简单的说,sub.cfc通过继承parent.cfc,就自动拥有了parent.cfc中的(constructor构造器中的)变量、属性和公开的(public)方法,比如:

<!--- parent.cfc --->
<cfcomponent>
  <cffunction name="getSth">
    <cfreturn "this is parent class">
  </cffunction>
</cfcomponent>

<!--- sub.cfc --->
<cfcomponent extends="parent">
  <cffunction name="getSthFromParent">
    <cfreturn super.getSth()>
  </cffunction>
</cfcomponent>
<!--- test.cfm --->
<cfset Obj = createObject("component", "sub")>
<cfset temp = Obj.getSthFromParent()>
<cfoutput>#temp#</cfoutput>

test.cfm将输出:“this is  parent class”