javascript
SamePlace spinoffs #1: CSS Query
Posted May 16th, 2007 by bardBefore:
var xulScriptlet;
var blueprint = document.getElementById('blueprints').firstChild;
while(blueprint) {
if(blueprint.getAttribute('class') == 'scriptlet')
break;
blueprint = blueprint.nextSibling;
}
var xulScriptlet = blueprint.cloneNode(true);
xulScriptlet.getElementsByAttribute('class', 'name')[0].value =
scriptlet.info.name;
xulScriptlet.getElementsByAttribute('class', 'version')[0].value =
scriptlet.info.version;
document.getElementById('scriptlets').appendChild(xulScriptlet);
After...
Memoize in JavaScript
Posted February 15th, 2007 by bardIn JavaScript, functions are objects. No big deal, until you expand that to functions can have state, and realize that things like this become possible:
function fact(n) {
var memo = arguments.callee.memo;
if(!(n in memo))
if(n == 0)
memo[n] = 1;
else
memo[n] = n * fact(n - 1);
return memo[n];
}
fact.memo = {};
(arguments.callee is how you reference a function from within the function itself.)
Comments
1 day 12 hours ago
1 day 12 hours ago
1 day 20 hours ago
2 days 58 min ago
2 days 11 hours ago
3 days 4 hours ago
4 days 4 hours ago
1 week 2 days ago
2 weeks 1 day ago
4 weeks 5 days ago