Advertisement
johnrom

Sniffing for Funcs & Vars

Sep 1st, 2012
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function functionOrVariableIsAvailable(name, type, tries) {
  2.     var iterator = tries || 1;
  3.  
  4.     if (type === 'function') {
  5.         // if you are using a function
  6.         dependencyAvailable = (typeof name === 'function') ? true : false;
  7.     } else if (type === 'variable') {
  8.         // if you are using a variable
  9.         dependencyAvailable = (typeof name !== 'undefined' && typeof name !== 'function') ? true : false;
  10.     }
  11.  
  12.     if (dependencyAvailable) {
  13.         return name;
  14.     } else if (iterator <= 10) {
  15.         iterator++;
  16.         setTimeout(function () {
  17.             functionOrVariableIsAvailable(name, type, iterator);
  18.         }, 500);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement