易截截图软件、单文件、免安装、纯绿色、仅160KB

为IE的javascript提速


我们知道,javascript在执行期时是由内到外执行脚本的,那么离我们的脚本最远的全局对象,很可能要跨越几层作用域对能访问到它。不过在IE中,从最内层到最外层要花的时间比其他多出很多。加之,javascript是一种胶水语言,它必须要调用DOM对能完成我们大多数选择。最著名的就是选择元素(document.getElementById,document.getElementsByTagName,docuemnt.evaluate,document.querySelector),创建元素(document.createElement),此外还有document.body,document.defaultView.getComputedStyle等等,频繁地调用document对象,但是document是位于window对象下,因此这路程就更远了。就了提速,我们必须把它们保存在一个本地变量,那么每次就省得它长途跋涉了。这种技术的运用明显体现在jQuery的源码中:
(function( window, undefined ) {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
//====================省=================
}
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
})(window);

把window传进闭包内,就省得它每次都往外找window了。
再看其他类库
//Raphael
window.Raphael = (function () {
var separator = /[, ]+/,
elements = /^(circle|rect|path|ellipse|text|image)$/,
doc = document,
win = window,
//************略**************

//dojo
d.global = this;

//Ext
DOC = document,

//YUI
//************略************
} else if (i == 'win') {
c[i] = o[i].contentWindow || o[i];
c.doc = c[i].document;
//************略************
Y.config = {
win: window || {},
doc: document,

但是如果你没有引入类库,


相关文档:

javascript开发系列(面向对像)

javascript中的面像对像。
请看代码,下面弹出一个对话筐。
  <script type="text/javascript">
        function win(w, h,,url)
         {
            this.widt ......

分享JavaScript在线压缩工具

This tool will let you optimize your JavaScript (JScript) code by removing comments, whitespace as well as other unnecessary characters as well as by optionally shortening function / variable / class names.
http://www.xtreeme.com/javascript-optimizer/ ......

IE与Firefox在JavaScript上的7个不同句法

尽管那需要用长串的、沉闷的不同分支代码来应付不同浏览器的日子已经过去,偶尔还是有必要做一些简单的区分和目标检测来确保某块代码能在用户的机器上正常运行。在这篇文章中,作者介绍了7个在IE和Firefox中不同的JavaScript句法。
1. CSS "float" 值
 
访问一个给定CSS 值的最基本句法是:object.style.property, ......

JavaScript语法集锦

click()对象.click()使对象被点击。
closed对象.closed对象窗口是否已关闭true/false
clearTimeout(对象)清除已设置的setTimeout对象
clearInterval(对象)清除已设置的setInterval对象
confirm("提示信息")弹出确认框,确定返回true取消返回false
cursor:样式更改鼠标样式handcrosshairtextwaithelpdefaultautoe/s/w/n ......

FireFox浏览器复制到剪贴板功能的javascript源代码

根据浏览器复制到剪贴板的功能,具体代码如下:
var txt="要复制到剪贴板的内容";
function copyToClipboard(txt) {
     if(window.clipboardData) {
             window.clipboardData.clearData();
    &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号