在javascript函数名中使用coldfusion变量

时间:2015-04-27 23:06:39

标签: javascript coldfusion

我在import comp102x.IO; //External library available in many of the later demo programs from https://courses.edx.org/courses/course-v1:HKUSTx+COMP102.1x+2T2015/f792f3a2057040aa959e606d687e9bc4/ /** * A class of Car objects that can move forward, backward and turn */ public class Car { private int odometer = 0; // An odometer reading initialized to 0 private String owner = "NoName"; // Name of owner /** * Default constructor for a Car object */ public Car () {} /** * Constructor for a Car object with a new owner’s name * @param name name of owner */ public Car(String name) { // Constructor takes a name as argument owner = name; } /** * moveCar moves a car forward or backward by dist units * @param dist Moving distance */ public void moveCar(int dist) { odometer = odometer + Math.abs(dist); IO.outputln(owner + "'s car has moved " + dist + " units."); } /** * turnCar turns a car by a given degree * @param angle Turn angle in degrees */ public void turnCar(double angle) { IO.outputln(owner + "'s car has turned " + angle + " degrees."); } /** * getOdometer gets the odometer reading of a car * @return The value of odometer */ public int getOdometer() { return odometer; } } 模板中有一个函数,可以在另一个页面中多次调用。问题是,我需要函数名称是动态的。有没有办法将ColdFusion变量与javascript函数名称连接?像这样:

CFML:

(defun first (x) (car x))
(defun rest (x) (cdr x))

JS:

.cfm

1 个答案:

答案 0 :(得分:4)

你可以这样做:

$(singletons [d| data Nat = Z | S Nat deriving (Eq, Show) |])

data Bounded n where
    BZ :: Bounded n
    BS :: Bounded n -> Bounded (S n)

succ :: SingI n => Bounded n -> Bounded n
succ bn = fromMaybe BZ $ go sing bn where
    go :: Sing n -> Bounded n -> Maybe (Bounded n)
    go  SZ      BZ     = Nothing
    go (SS ny)  BZ     = Just (BS BZ)
    go (SS ny) (BS bn) = BS <$> go ny bn

但你更有可能想要这样做:

<script type="text/javascript">

  <cfoutput>
    function name#id#()
  </cfoutput>
</script>