javascriptµÄº¯Êýµ÷Óü̳ÐʵÏÖ
¿´µ½Ò»ÆªÈëÃŵÄJS¼Ì³ÐÎÄÕÂ,×ªÔØÏÂ
ÔµØÖ·:http://sdcyst.javaeye.com/blog/288813
Àà±äÁ¿/Àà·½·¨/ʵÀý±äÁ¿/ʵÀý·½·¨
ÏȲ¹³äÒ»ÏÂÒÔǰд¹ýµÄ·½·¨:
ÔÚjavascriptÖÐ,ËùÓеķ½·¨¶¼ÓÐÒ»¸öcall·½·¨ºÍapply·½·¨.ÕâÁ½¸ö·½·¨¿ÉÒÔÄ£Äâ¶ÔÏóµ÷Ó÷½·¨.ËüµÄµÚÒ»¸ö²ÎÊýÊǶÔÏó,ºóÃæµÄ
²ÎÊý±íʾ¶ÔÏóµ÷ÓÃÕâ¸ö·½·¨Ê±µÄ²ÎÊý(ECMAScript specifies two methods that are defined for all functions, call()
and apply(). These methods allow you to invoke a function as if it were a method of some other object. The first
argument to both call() and apply() is the object on which the function is to be invoked; this argument becomes
the value of the this keyword within the body of the function. Any remaining arguments to call() are the values
that are passed to the function that is invoked).±ÈÈçÎÒÃǶ¨ÒåÁËÒ»¸ö·½·¨f(),È»ºóµ÷ÓÃÏÂÃæµÄÓï¾ä:
f.call(o, 1, 2);
×÷ÓþÍÏ൱ÓÚ
o.m = f;
o.m(1,2);
delete o.m;
¾Ù¸öÀý×Ó:
Js´úÂë < type="application/x-shockwave-flash" width="14" height="15" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=function%20Person(name%2Cage)%20%7B%20%20%2F%2F%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%0A%20%20%20%20this.name%20%3D%20name%3B%0A%20%20%20%20this.age%20%3D%20age%3B%0A%7D%0Avar%20o%20%3D%20new%20Object()%3B%20%20%20%2F%2F%E7%A9%BA%E5%AF%B9%E8%B1%A1%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fundefined_undefined%0A%0APerson.call(o%2C%22sdcyst%22%2C18)%3B%20%2F%2F%E7%9B%B8%E5%BD%93%E4%BA%8E%E8%B0%83%E7%94%A8%3Ao.Person(%22sdcyst%22%2C18)%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fsdcyst_18%0A%0APerson.apply(o%2C%5B%22name%22%2C89%5D)%3B%2F%2Fapply%E6%96%B9%E6%B3%95%E4%BD%9C%E7%94%A8%E5%90%8Ccall%2C%E4%B8%8D%E5%90%8C%E4%B9%8B%E5%A4%84%E5%9C%A8%E4%BA%8E%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0%E7%9A%84%E5%BD%A2%E5%BC%8F%E6%98%AF%E7%94%A8%E6%95%B0%E7%BB%84%E6%9D%A5%E4%BC%A0%E9%80%92%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fname_89" qua
Ïà¹ØÎĵµ£º
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
&nb ......
ÇëÏÈ¿´ÏÂÌ⣺
if(true)
{
a = 1;
}
alert(a); //Êä³öɶ£¿
if(true)
{
var a = 1;
}
alert(a); //ÕâÓÖÊä³öʲô£¿
ÔÚfirefox3.5Ï£¬µÚÒ»¸öÊä³ö1;µÚ¶þ¸öÊä³öundefined£¡£¡£¡
ÎªÉ¶ÄØ£¿ºÇºÇ£¬±¾ÈËÔڴ˰àÃÅŪ¸«Ò»Ï£º
Ò»°ãÇé¿öÏÂȱʡvarÉùÃ÷ʱ£¬Ä¬È ......
AS("#...").keypress(function(event) {
if (navigator.userAgent.toLowerCase().indexOf("mozilla") >= 0) {
var $key = event.charCode ;
} else {
var $key = event. ......
C#´úÂëÓëjavaScriptº¯ÊýµÄÏ໥µ÷ÓÃ
ÎÊ£º
1.ÈçºÎÔÚJavaScript·ÃÎÊC#º¯Êý?
2.ÈçºÎÔÚJavaScript·ÃÎÊC#±äÁ¿?
3.ÈçºÎÔÚC#ÖзÃÎÊJavaScriptµÄÒÑÓбäÁ¿?
4.ÈçºÎÔÚC#ÖзÃÎÊJavaScriptº¯Êý?
ÎÊÌâ1´ð°¸ÈçÏ£º
javaScriptº¯ÊýÖÐÖ´ÐÐC#´úÂëÖеĺ¯Êý£º
·½·¨Ò»£º1¡¢Ê×ÏȽ¨Á¢Ò»¸ö°´ ......