forked from nyarly/NinjaScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Behavior Resolvable
Judson edited this page Jul 7, 2011
·
2 revisions
There are several syntaxes that are legitimate to use inside of a Ninja.behavior()
definition. They are:
- A Behavior object
- NinjaScript defines a constructor for Behavior objects – you’re unlikely to use them directly since the Behavior constructor is encapsulated inside the Ninja definition scope – but there are a number of methods that return a Behavior
- A Metabehavior object
- Metabehaviors are able to select what Behavior to apply given the tag they’re applied to. Otherwise, alike to Behaviors.
- A function
- You can use a function that returns a Behavior, and NinjaScript will use the result of calling the function with no arguments.
- A behavior definition
- You can give NinjaScript an object suitable as a behavior definition as the value bound to a selector. If you aren’t using a packaged behavior, this is the most common form – we call them ad hoc behaviors.
- An array of the above
- Multiple behaviors can be applied to the same element – their composition is a little tricky but powerful. An array will apply each of the behaviors in turn.