注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

享受编码

    的乐趣

 
 
 

日志

 
 

JavaScript needs modules!  

2010-07-09 09:51:48|  分类: JavaScript |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
JavaScript needs modules!

I’ve just given my breakout session, “JavaScript needs modules!“, at the Mozilla Summit. (Note: none of this is implemented yet, so please don’t take any of the code snippets too literally.)

The enthusiastic atmosphere at the summit has been palpable– it’s hard not to be in awe of my coworkers and fired up for what’s ahead for the web. For my part, I believe that modules are one of the most important upcoming features of JavaScript, and I also believe we can make them happen.

This entry was posted on Thursday, July 8th, 2010 at 2:29 pm and is filed under Uncategorized. You can follow any comments to this entry through the RSS 2.0 feed. You can leave a comment, or trackback from your own site.



2 comments

Cannot agree more.
Would love to be able to do a require(”) like in Node.js.

It’s a hack but for now people can simply do the following:

var require = function(jsfile,callback) {
               var script_tag = document.createElement(’script’);
               script_tag.setAttribute(“type”,”text/javascript”);
               script_tag.setAttribute(“src”, jsfile);

        if(typeof callback == ‘function’) {
                              script_tag.onload = callback;
                              script_tag.onreadystatechange = function () { // IE
                                             if (this.readyState == ‘complete’ || this.readyState == ‘loaded’) {
                                                            callback();
                                             }
                              };
               }

        (document.getElementsByTagName(“head”)[0] || document.documentElement).appendChild(script_tag);

};

  评论这张
 
阅读(626)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017