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 week 3 days ago
2 weeks 14 hours ago
2 weeks 1 day ago
2 weeks 3 days ago
2 weeks 6 days ago
2 weeks 6 days ago
3 weeks 1 day ago
3 weeks 1 day ago
4 weeks 1 day ago
5 weeks 5 days ago