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

[翻译]High Performance JavaScript(020)

Yielding with Timers  用定时器让出时间片
    Despite your best efforts, there will be times when a JavaScript task cannot be completed in 100 milliseconds or less because of its complexity. In these cases, it's ideal to yield control of the UI thread so that UI updates may occur. Yielding control means stopping JavaScript execution and giving the UI a chance to update itself before continuing to execute the JavaScript. This is where JavaScript timers come into the picture.
    尽管你尽了最大努力,还是有一些JavaScript任务因为复杂性原因不能在100毫秒或更少时间内完成。这种情况下,理想方法是让出对UI线程的控制,使UI更新可以进行。让出控制意味着停止JavaScript运行,给UI线程机会进行更新,然后再继续运行JavaScript。于是JavaScript定时器进入了我们的视野。
Timer Basics  定时器基础
    Timers are created in JavaScript using either setTimeout() or setInterval(), and both accept the same arguments: a function to execute and the amount of time to wait (in milliseconds) before executing it. The setTimeout() function creates a timer that executes just once, whereas the setInterval() function creates a timer that repeats periodically.
    在JavaScript中使用setTimeout()或setInterval()创建定时器,两个函数都接收一样的参数:一个要执行的函数,和一个运行它之前的等待时间(单位毫秒)。setTimeout()函数创建一个定时器只运行一次,而setInterval()函数创建一个周期性重复运行的定时器。
    The way that timers interact with the UI thread is helpful for breaking up long-running scripts into shorter segments. Calling setTimeout() or setInterval() tells the JavaScript engine to wait a certain amount of time and then add a JavaScript task to the UI queue. For example:
    定时器与UI线程交互的方式有助于分解长运行脚本成为较短的片断。调用setTimeout()或setInterval()告诉JavaScript引擎等待一定时间然后将JavaScript任务添加到UI队列中。例如:
function greeting(){
  alert("Hello world!");
}
setTimeout(gree


相关文档:

javascript继承方式之三

3、组合构造函数/原型方式写类,采用前面种方式继承
这种方式父类,子类的属性都挂在构造函数里,方法都挂在原型上。
/**
* 父类Polygon:多边形
*/
function Polygon(sides) {
this.sides = sides;
}
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
* Triangle 三角形
* @param {Object} b ......

JavaScript基础知识1

Javascript数据类型
由于javascript是弱类型语言,即定义变量时不必声明其类型
。但这并不意味着变量没有类型。因为赋值时会自动匹配数据类型!
目前用到的基本数据类型
number
boolean
string
var i
i="test";//这时i就成了string类型
var i
i=4;//这时i就成了number类型
常用对象类型<object> ......

[翻译]High Performance JavaScript(014)

Recursion Patterns  递归模式
    When you run into a call stack size limit, your first step should be to identify any instances of recursion in the code. To that end, there are two recursive patterns to be aware of. The first is the straightforward recursive pattern represented ......

[翻译]High Performance JavaScript(015)

第五章  Strings and Regular Expressions  字符串和正则表达式
    Practically all JavaScript programs are intimately tied to strings. For example, many applications use Ajax to fetch strings from a server, convert those strings into more easily usable JavaScript objects, and ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号