new PropertyEvaluator(target)
Evaluates a type string expression and return the property value who corresponding in the target object specified in this evaluator.
Evaluates a type string expression and return the property value who corresponding in the target object specified in this evaluator.
Parameters:
Name | Type | Description |
---|---|---|
target |
object | The object to evaluates. |
Example
var PropertyEvaluator = system.evaluators.PropertyEvaluator ; var obj = { message : "hello world" , title : "my title" , menu : { title : "my menu title" , label : "my label" } } var evaluator = new PropertyEvaluator( obj ) ; // valid expressions trace( evaluator.eval( "message" ) ) ; // hello world trace( evaluator.eval( "title" ) ) ; // my title trace( evaluator.eval( "menu.title" ) ) ; // my menu title trace( evaluator.eval( "menu.label" ) ) ; // my label // invalid expressions trace( evaluator.eval( "" ) ) ; // null trace( evaluator.eval( "unknow" ) ) ; // null trace( evaluator.eval( "menu.unknow" ) ) ; // null // change the "undefineable" value returns in the eval() method when the evaluation failed. evaluator.undefineable = "empty" ; trace( evaluator.eval( "unknow" ) ) ; // empty ; evaluator.undefineable = undefined ; trace( evaluator.eval( "unknow" ) ) ; // undefined ; // activate the throwError mode. evaluator.throwError = true ; try { evaluator.eval( "test" ) ; } catch( e ) { trace( e ) ; // ##EvalError: [object PropertyEvaluator] eval failed with the expression : test## }
Extends
Members
-
separator :string
-
The separator character of the expression evaluator.
Type:
- string
- Default Value:
-
- '.'
-
target :object
-
The target reference use in the evaluator.
Type:
- object
-
throwError :boolean
-
Indicates if the eval() method throws errors or return null when an error is throwing.
Type:
- boolean
- Default Value:
-
- false
-
undefineable :object
-
Defines the value returns from the eval() method if the expression can't be evaluate.
Type:
- object
- Default Value:
-
- null
Methods
-
eval(value)
-
Evaluates the specified object.
Parameters:
Name Type Description value
* The object to evaluates.
- Overrides:
Returns:
The result of the evaluation.
-
toString()
-
Returns the string representation of this instance.
- Overrides:
Returns:
the string representation of this instance.