javascriptÖеijÉÔ±º¯Êýµ÷ÓõÄÒ»¸öСÎÊÌâ
Ê×ÏÈ¿´demo´úÂ룺
var student={
name:"leo",
intro:function(){
alert("my name is "+this.name);
}
}
var teacher=function(f){
f();
}
teacher(student.intro);
ÔÚÉÏÃæµÄdemo£¬¿ÉÒÔ¿´µ½ÏÔʽµÄ¶¨ÒåÁËÒ»¸ö¶ÔÏóstudent£¬ÓÐÒ»¸ö³ÉÔ±º¯ÊýintroºÍÒ»¸ö³ÉÔ±±äÁ¿¡£
ÁíÍⶨÒåÁËÒ»¸öº¯Êýteacher£¬½ÓÊÜÒ»¸öº¯Êý×÷Ϊ²ÎÊý£¬²¢µ÷ÓÃÁËÕâ¸öº¯Êý¡£
ÊÔÔËÐУ¬ÎÒÃǽ«studentµÄ³ÉÔ±º¯Êýintro×÷Ϊ²ÎÊý´«¸øteacherº¯Êýµ÷Óᣱ¾À´intro»á·ÃÎÊstudentµÄ³ÉÔ±±äÁ¿name£¬µ«ÊÇÔÚʵ¼ÊÔËÐÐÖÐÈ´²»ÏñÎÒÃÇÏëµÄÄÇÑù£¬±»teacherµ÷ÓÃÒÔºó£¬introÄÚ²¿Ê¹ÓõÄthis¾Í²»ÊÇÖ¸Ïòstudent¶øÊÇÖ¸Ïòwindow¶ÔÏóÁË¡£
¿ÉÒÔ¿´µ½£¬ÕâÖÖÇé¿öÏ£¬³ÉÔ±º¯ÊýʧȥÁËËû±¾ÉíµÄ¶ÔÏó»·¾³£¬¶ø±©Â¶ÔÚÍâÃæ×÷Ϊwindow¶ÔÏóµÄ³ÉÔ±º¯ÊýÁË¡£
Õâ¸öÀý×Ó¿ÉÒÔ°ïÖúÎÒôÀí½âjavascriptµÄÔËÐлúÖƺͶÔÏó»úÖÆ¡£
ÁíÍ⣬ÕâÖÖÇé¿öµÄ½â¾ö·½·¨£¬ÎÒ¾õµÃÊÇÀûÓÃcaller»òÕßcalleeÀ´×ö£¬¾ßÌåÈçºÎ×ö£¬»¹Óдý½øÒ»²½ÊµÑé¡£
Ïà¹ØÎĵµ£º
//ºǫ́CSµ÷ÓÃǰ̨JS·½·¨
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script>CheckInput()</script>");
//УÑéÊäÈë¿òÊÇ·ñΪ¿Õ£¬Ð£ÑéÊÇ·ñÊÇÊý×Ö
<script type="text/javascript" language="javascript">
function CheckInput ......
1¡¢¶ÔÏóµÄ¼Ì³Ð£¬Ò»°ãµÄ×ö·¨ÊǸ´ÖÆ£ºObject.extend
prototype.jsµÄʵÏÖ·½Ê½ÊÇ£º
Object.extend = function(destination, source){
for (property in source) {
destination[property] = source[property];
}
return destination;
......
ÔÚjsÖУ¬Ã¿¸ö¶ÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ£º·µ»Ø¶ÔÏóÀàÐÍÔÐ͵ÄÒýÓ᣺ÜÞÖ¿Ú£¡Ï°Óï“ÒÀºù«»Æ°”£¬ÕâÀïµÄºù«¾ÍÊÇÔÐÍ£¬ÄÇô“Æ°.prototype” ·µ»ØµÄ¾ÍÊǺù«£¬»òÕß“Æ°.prototype= new ºù«()”¡£
prototypeµÄÓÃ;£º
¼Ì³Ð
ÓÐÒ»¸ö¶ÔÏó££×ÓÀࣺ
function ×ÓÀà() {
this.lastname = ......
¶¨ÒåÓëÓ÷¨
The prototype property allows you to add properties and methods to an
object.
prototypeÊôÐÔÔÊÐíÄãÏòÒ»¸ö¶ÔÏóÌí¼ÓÊôÐԺͷ½·¨
Syntax
Óï·¨
object.prototype.name=value
Example 1
ʵÀý
In this example we will show how to use the prototype property to add a
property to an object:
ÔÚÏÂ ......
·µ»Ø JavaScript È«¾Ö¶ÔÏó²Î¿¼ÊÖ²á
¶¨ÒåºÍÓ÷¨
isNaN() º¯ÊýÓÃÓÚ¼ì²éÆä²ÎÊýÊÇ·ñÊÇ·ÇÊý×ÖÖµ¡£
Óï·¨
isNaN(x)
²ÎÊýÃèÊö
x
±ØÐè¡£Òª¼ì²âµÄÖµ¡£
·µ»ØÖµ
Èç¹û x ÊÇÌØÊâµÄ·ÇÊý×ÖÖµ NaN£¨»òÕßÄܱ»×ª»»ÎªÕâÑùµÄÖµ£©£¬·µ»ØµÄÖµ¾ÍÊÇ true¡£Èç¹û x ÊÇÆäËûÖµ,Ôò·µ»Ø false¡£
˵Ã÷
isNaN() º¯Êý¿ÉÓÃÓÚÅжÏÆä²ÎÊýÊÇ·ñÊÇ NaN£ ......