[·Òë]High Performance JavaScript(006)
Identifier Resolution Performance ±êʶ·ûʶ±ðÐÔÄÜ
Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for both reads and writes. Consequently, local variables are always the fastest to access inside of a function, whereas global variables will generally be the slowest (optimizing JavaScript engines are capable of tuning this in certain situations). Keep in mind that global variables always exist in the last variable object of the execution context's scope chain, so they are always the furthest away to resolve. Figures 2-4 and 2-5 show the speed of identifier resolution based on their depth in the scope chain. A depth of 1 indicates a local variable.
±êʶ·ûʶ±ð²»ÊÇÃâ·ÑµÄ£¬ÊÂʵÉÏûÓÐÄÄÖÖµçÄÔ²Ù×÷¿ÉÒÔ²»²úÉúÐÔÄÜ¿ªÏú¡£ÔÚÔËÐÐÆÚÉÏÏÂÎĵÄ×÷ÓÃÓòÁ´ÖУ¬Ò»¸ö±êʶ·ûËù´¦µÄλÖÃÔ½ÉËüµÄ¶ÁдËٶȾÍÔ½Âý¡£ËùÒÔ£¬º¯ÊýÖоֲ¿±äÁ¿µÄ·ÃÎÊËÙ¶È×ÜÊÇ×î¿ìµÄ£¬¶øÈ«¾Ö±äÁ¿Í¨³£ÊÇ×îÂýµÄ£¨ÓÅ»¯µÄJavaScriptÒýÇæÔÚijЩÇé¿öÏ¿ÉÒԸıäÕâÖÖ×´¿ö£©¡£Çë¼Çס£¬È«¾Ö±äÁ¿×ÜÊÇ´¦ÓÚÔËÐÐÆÚÉÏÏÂÎÄ×÷ÓÃÓòÁ´µÄ×îºóÒ»¸öλÖã¬ËùÒÔ×ÜÊÇ×îÔ¶²ÅÄÜ´¥¼°µÄ¡£Í¼2-4ºÍ2-5ÏÔʾÁË×÷ÓÃÓòÁ´Éϲ»Í¬Éî¶È±êʶ·ûµÄʶ±ðËÙ¶È£¬Éî¶ÈΪ1±íʾһ¸ö¾Ö²¿±äÁ¿¡£
Figure 2-4. Identifier resolution for write operations
ͼ2-4 д²Ù×÷µÄ±êʶ·ûʶ±ðËÙ¶È
Figure 2-5. Identifier resolution for read operations
ͼ2-5 ¶Á²Ù×÷µÄ±êʶ·ûʶ±ðËÙ¶È
The general trend across all browsers is that the deeper into the scope chain an identifier exists, the slower it will be read from or written to. Browsers with optimizing JavaScript engines, such as Chrome and Safari 4, don't have this sort of performance penalty for accessing out-of-scope identifiers, whereas Internet Explorer, Safari 3.2, and others show a more drastic effect. It's worth noting that earlier browsers, such as Internet Explorer 6 and Firefox 2, had incredibly steep slopes and would no
Ïà¹ØÎĵµ£º
//ÏÔʾµ±Ç°Ê±¼ä----------------------------------------------------------
<SCRIPT language="javascript" type="text/javascript" >
function reloop(){
var time = new Date( ); //»ñµÃµ±Ç°Ê±¼ä
//»ñµÃÄê¡¢Ô¡¢ÈÕ£¬Date()º¯ÊýÖеÄÔ·ÝÊÇ´Ó0£11¼ÆËã
var year = time.getFullYear ......
Ò³ÃæÒ»£º
<html>
<head>
<title> ÑéÖ¤ÓëÌá½»Ò» </title>
<script>
function focusSelect(ID) //µ±ÑéÖ¤²»ÄÜͨ¹ýʱ»ñµÃÑéÖ¤¿Ø¼þµÄ½¹µãºÍÄÚÈÝ
{
document.getElementById(I ......
1.ÔÚHTMLÖÐʹÓÃ<script>ÔªËØÒýÈëJavaScript¡£
¸ÃÔªËØÓÐÁ½¸öÊôÐÔ£¬languageÉùÃ÷ҪʹÓõĽű¾ÓïÑÔ£¬srcÊôÐÔÊÇ¿ÉÑ¡µÄ£¬ÓÃÓÚÒýÓÃÍⲿJavaScriptÎļþ¡£
NB
£ºÏÖÔÚ´ó¶àʹÓÃtypeÊôÐÔ£¨type=“text/javascript”£©Ìæ´úlanguageÊôÐÔ£¬ÒÔ±ã¸üºÃµØÖ§³ÖXHTML£¨¿ÉÀ©Õ¹HTML£©¡£
2.Ò»°ãÈÏΪ ......
phpÖеÄevalºÍJavaScriptÖеÄevalÇø±ð£º
Definition and Usage
¶¨ÒåºÍÓ÷¨
The eval() function evaluates a
string as PHP code.
eval()º¯ÊýµÄ×÷ÓÃÊÇ£º·µ»ØÓëPHP´úÂëÏà¶ÔÓ¦µÄ×Ö·û´®¡£
The string
must be valid PHP code and must end with semicolon.
Õâ¸ö×Ö·û´®±ØÐëÊÇÓÐЧµÄPHP´úÂ룬
²¢ÇÒ±ØÐëÒԷֺŽáÊø¡ ......
µÚ¶þÕ£ºECMAScript»ù´¡
1.µ±º¯ÊýÎÞÃ÷È··µ»ØÖµÊ±£¬·µ»ØµÄÒ²ÊÇÖµundefined
function testFunc(){}
alert(testFunc()==undefined);
2.typeof(null)=='object' //true,null¿ÉÒÔ½âÊÍΪ¶ÔÏóռλ·û
3.undefined ÊÇÉùÃ÷Á˱äÁ¿µ«Î´¶ÔÆä³õʼ»¯Ê±¸³Óè¸Ã±äÁ¿µÄÖµ£¬nullÔòÓÃÓÚ±íʾÉÐδ´æÔڵĶÔÏó¡£
alert(nu ......