UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

99 lines (82 loc) 3.48 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://an3m1.com/" rel="nofollow">???? ????????</a> </strong> on 2012-04-10 09:56:27 <br /> If I might —perhaps you should consider adding a few images. I don’t mean to disrespect what you’ve said ; its very enlightening, indeed. However, I think would respond to it more positively if they could be something tangible to your ideas <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-12-30 12:36:56 <br /> @ Brett Zamir: Awesome! <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2008-12-21 06:40:17 <br /> And here's get_defined_vars(). As far as iterating deeper over its object properties to get a few other globals, the function turns up 'document' and 'location' which would not otherwise be present. <pre><code> function get_defined_vars() { var i = '', ct = 0, obj = {}; for (i in window) { try { // if (typeof window[i] !== 'function') { // Uncomment if wish to ignore functions (though in JavaScript, they really are variables) // sessionStorage gives errors here in Mozilla obj[i] = window[i]; if (typeof window[i] === 'object') { for (var j in window[i]) { // 'history', 'globalStorage' gives errors here in Mozilla if (window[j] !== undefined) { // window/parent/top/frames/self give errors here in Mozilla // if (typeof window[j] !== 'function') { // Uncomment if wish to ignore functions (though in JavaScript, they really are variables) obj[j] = window[j]; // } } } } // } } catch (e) { } ct++; } // window.length = ct; // Uncomment if wish to create an array-like object return obj; }</code></pre> <hr /> <strong> Brett Zamir </strong> on 2008-12-21 03:30:10 <br /> Here's a slight improvement...For some reason, in Mozilla at least, you actually have to iterate over the window properties which are objects to get a few other globals not returned by a mere iteration of window itself (in Mozilla, these are: QueryInterface, addEventListener, getComputedStyle). <pre><code>function get_defined_functions() { // http://kevin.vanzonneveld.net // + original by: Brett Zamir // % note 1: Test case 1: If get_defined_functions can find itself in the defined functions, it worked :) // * example 1: function test_in_array(array, p_val) {for(var i = 0, l = array.length; i &amp;lt; l; i++) {if(array[i] == p_val) return true;} return false;} // * example 1: funcs = get_defined_functions(); // * example 1: found = test_in_array(funcs, 'get_defined_functions'); // * results 1: found == true var i = '', arr = [], already = {}; for (i in window) { try { if (typeof window[i] === 'function') { if (!already[i]) { already[i] = 1; arr.push(i); } } else if (typeof window[i] === 'object') { for (var j in window[i]) { if (typeof window[j] === 'function' &amp;amp;&amp;amp; window[j] &amp;amp;&amp;amp; !already[j]) { already[j] = 1; arr.push(j); } } } } catch (e) { } } return arr; } </code></pre> <hr />