endflow.net blog

/* programming and programming */

Utility functions in JavaScript

without comments

/* Tested on Firefox 3 */

function $x(x,c){c=c||document;var d=c.ownerDocument||c;
var r=d.evaluate(x,c,null,4,null);for(var i,n=[];i=r.iterateNext();n.push(i));return n}
function $X(x,c){var e=$x(x,c)[0];e&&(arguments.callee.$=e);return e}
function $n(t,o,c){var e = document.createElement(t);if(o){for(var k in o)
{e[k]=o[k]}}if(c){c.forEach(function(ch){e.appendChild(ch)})}return e}
function $t(t){return document.createTextNode(t)}
function $(id){return document.getElementById(id)}
function $b(o,f){return function(){return f.apply(o,arguments)}}
function $e(t,o){t=t.toString();for(var k in o){t=t.replace(new RegExp('#{'+k+'}','g'),o[k])}return t}
function $h(o,a){if(a.length==0)return false;return a.every(function(p){return o.hasOwnProperty(p)})}
function isO(o){return o.constructor.toString()==Object.toString()}
function isA(a){return a.constructor.toString()==Array.toString()}
function isS(s){return (typeof s)=='string'}
function diffA(a,b){b.forEach(function(i){var p=a.indexOf(i);
if(p!=-1){a=a.slice(0,p).concat(a.slice(p+1))}});return a}
function interA(a,b){return a.filter(function(i){return b.indexOf(i)!=-1})}
function unionA(a,b){(a.length

enjoy JS! ;)

Written by kuy

October 14th, 2008 at 3:40 am

Posted in Uncategorized

Tagged with , ,

Leave a Reply