Too much recursion 

Higher Order Javascript


   Subscribe in NewsGator Online    Subscribe in Rojo    Add to Google      Add to My AOL   Subscribe in FeedLounge   Add to netvibes  

Brendan Eich's Roadmap  Standard ECMA-262  Yahoo! UI Library     

Thursday, July 27, 2006


Higher Order DOM Scripting

Here is an example of using functional programming to speed up DOM scripting. We'll take a Quirksmode text select script, (beautiful in its own right), and give it the functional treatment.
After the first function call(in this case), or after initialization, what this type of programming gives us is a function that no longer needs any environment object checks. This is as fast as browser programming can get.
//Select text from
function getSel(){
if (window.getSelection){
getSel=function(){return window.getSelection() }; return getSel() }
else if (document.getSelection){
getSel=function(){return document.getSelection()};return getSel() }
else if (document.selection){
getSel=function(){return document.selection.createRange().text};return getSel() }
else {getSel=function(){return null}}
document.onmouseup=function(){ alert(getSel()) };

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


June 2006   July 2006   August 2006   September 2006  

This page is powered by Blogger. Isn't yours?