优雅的javaScript代码

本文展示了一个简洁优雅的RSS阅读器实现方案,通过JavaScript代码解析RSS并展示内容,介绍了fooFeeds类的方法及其使用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一直以为javaScript意味着杂乱的全局变量,让人头疼的临时对象,乱七八糟毫无组织的函数。看来以前肯定是让人误导了。

下面是一个简单的rss阅读器,被<<Professional Ajax>>拿来介绍rss。感觉真的很优雅。

function loadIt(fileName)
    {
      fd 
= document.getElementById("feedisplay");      
      
var fs = new fooFeeds(fileName+".xml"); 
      fs.init();
      
      
if (fs.currChannel().feedTitle)    
        fd.innerHTML 
= "<h2>"+fs.currChannel().feedTitle+"</h2>";       
      
for (var i = 0; i<fs.numFeeds(); i++, fs.nextFeed())        
      {
        fdItem 
= document.createElement("div");
        fdItem.innerHTML 
= "<span class="icon"></span><a href=""+fs.currentFeed().link+"">"+fs.currentFeed().name+"</a>";
        fdItem.className 
= "title";
        document.getElementById(
"feedisplay").appendChild( fdItem );
        
        
if (fs.currentFeed().caption)
        {
          caption 
= document.createElement("div");
          caption.innerHTML 
= fs.currentFeed().caption;
          caption.className 
= "item";
            document.getElementById(
"feedisplay").appendChild( caption );
        }
        
        
delete fs;
      }
    }
/*  fooFeeds contains the following PUBLIC methods:
  
      init               =    loads XML file and parses data into channels
      numFeeds( int )     =    returns the number of Feeds;
                              omit int value to return count of current Channel
                            returns 0 if channel[int] does not exist
      currFeedNum      =   returns the current Feed number
      nextFeed         =   returns next Feed object in current Channel
      prevFeed         =   returns previous Feed object in current Channel
      currentFeed        =    returns current Feed object in current Channel
      nextChannel            =    returns next Channel object in list
      prevChannel            =    returns previous Channel object in list
      currentChannel        =    returns current Channel object
      
  
*/
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值