Prev | Current Page 492 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Template(???$$sayHelloTo(::user::)???);
var out = t.execute({
user : ???John???
},{
sayHelloTo: function(resolve: String- > Dynamic, name: String) {
return ???Hello ???+name+???!???;
}
});
trace(out);
}
}
(continued)
Chapter 10: Separating Design Using Templates
257
A new argument has been passed to the execute() method. This object contains one or more references
to the functions that are needed in the template execution. In the previous example, the sayHelloTo()
function must be invoked by using the field name prefixed with two dollar characters $ $ . The function is
invoked by using the user variable as a parameter. In macros it is also possible to pass constant string
values; simply put the value without the enclosing :: symbols.
The second thing to note is that the callback function has a formal signature: The first argument must
be a function (automatically passed by the template system) that helps to recall other values contained
in the template context; other arguments are optional and it is up to the developer to decide what he
may need.


Pages:
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504