This AI is still in early stages of development.
Check.has()
- Aubergine
Owned by Aubergine
Check if a dependency is available, try and load it if not, return availability state...
Syntax
var available = Check.has(file[, ver[, lazy]])
Parameters
Parameter | Type | Mandatory | Notes | Util.js version |
---|---|---|---|---|
file | String | Filename of dependency | 1.0 | |
ver | Number Constant | Specify the required version of the file (exact match) or a version constant:
Default: Check.ANY_VERSION For more information on autolaoding, see: Check.paths[]. | 1.0 | |
lazy | Constant | By default, Check.has() will attempt to autoload missing dependencies. If you want to prevent autoloading, specify Check.LAZY_LOAD | 1.0 |
Return Values
Value | Type | Notes | Util.js version |
---|---|---|---|
true | Boolean | The dependency check was successful. | 1.0 |
false | Boolean | The dependency check failed. | 1.0 |
<error> | Error | An error occurred, most likely invalid parameters. | 1.0 |
Example
Check specific version of file...
function bleh() { if (Check.has("foo.js", 1.2)) { // do it the foo.js v1.2 way } else { // do it without any foo } }
Prevent autoloading foo.js...
function bleh() { if (Check.has("foo.js", 1.2, Check.LAZY_LOAD)) { // do it the foo.js v1.2 way } else { // do it without any foo } }
Notes
You can get a list of all provided dependencies using Util API diagnostics (requires Diag API).
Contents
Jump to:
Dependency Checking
Topics:
- Tricks for including files — Some tricks with the include() function...
- Dependency Descriptor Object — Define one or more dependencies for your script...
- Check() — Perform a soft-check to see if a dependency is available...
- Check.basePath — The base path to the folder that contains the APIs folder...
- Check.paths[] — Define one or more folder paths to enable autoloading...
- Check.doWhen() — Perform a task when dependencies become available.
- Check.has() — Check if a dependency is available, try and load it if not, return availability state...
- Check.LAZY_LOAD — Disable autoloading during a dependency check...
- Check.required() — Thrown a descriptive error if dependency check fails...
- Check.NOT_LOADED — Indicates a script is not yet loaded, or must not be loaded, depending on the Check function being used...
- Check.ANY_VERSION — Skip version checking for a dependency check...
- Check.provide() — Indicate a file is now available.
- Check.versionOf() — Check the version of a dependency.
- Self Descriptor Object — Define the filename and version of your script...