Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Check if a context has a function property, optionally with specified number of formal parameters... |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
hasFunction( context, key[, paramCount] ); |
Parameters
Parameter | Type | Mandatory | Notes | API Version |
---|---|---|---|---|
context | Variant | The object to which the function is attached. | 1.5 | |
key | String | The name of the property that should be a function. | 1.5 | |
paramCount | Number | The number of formally defined parameters the function should have. Default: Don't check parameter count. | 1.5 |
Return Values
Value | Type | Notes | API Version |
---|---|---|---|
<error> | Error | Most likely the parameters are wrong. | 1.0 |
true | Boolean | The assertion passed. | 1.0 |
false | Boolean | The assertion failed. | 1.0 |
Notes
The assertion is performed in three stages:
- Assert that the property 'key' exists
- Assert that the value of the property is a function
- If paramCount specified, assert the number of formal parameters matches paramCount
The message added to the test results indicates indicates which stage hasFunction( ) had got to when the assertion passed or failed.
Example
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// let's say we're testing this... var _global.foo = { bar: function(a, b, c) {};}, chimp: "not a function" } Test("_globalfoo.foobar() defined", Test.ANY( ), function() { hasFunction( _globalfoo, "bar" ); // passes hasFunction( foo, "chimp" ); // fails - chimp is not a function hasFunction( foo, "bar", 3 ); // passes hasFunction( _globalfoo, "foobar", 4 ); // passes fails - bar() has 3 formal params }); |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
Test APITopics:
|