Adding missing functions
Overview
Backport allows you to implement missing functions by providing your own functions.Availability
Backport v0.1 and above.
Syntax
if (!backport(functionName)) { // function is missing, need to add it var status = backport(functionName,function(...) { // do stuff }); // status === 1 indicates that all went well } // then elsewhere in the code access the function as usual var foo = functionName(params);
Parameters
Parameter | Type | Mandatory | Description | Backport version |
---|---|---|---|---|
functionName | String | The name of the function to check/create | 0.1 | |
<function> | Function | The function to assign to functionName | 0.1 |
Return values
See status return values.
Examples
See the following backport scripts for great examples:
- objFromId.js – very simple example of function addition
- backport.orderDroid.js – more advanced function addition/upgrade, also has a little API to extend what orders it can accept
See also
- Accessing native API features – bypass any backports to access native versions of JS API features
- Adding missing constants – if your function uses constants, you'll probably need to add missing constants too
- Check status of an API feature – work out whether a JS API feature exists and whether it's been altered by backport