Ò»¾ä»°Àí½âjavascript prototypeÊôÐÔ
Õâ¾ä»°ÊÇ£ºprototypeÖж¨ÒåµÄÊǶÔÏóʵÀýÒª·ÃÎʵÄÊôÐÔ»ò·½·¨µÄÒ»¸öÌæ²¹¡£
¾ÙÀý˵Ã÷һϣº
//1£©¶¨ÒåÁËÒ»¸ö¶ÔÏó£º
function A()
{
//¸ø¶ÔÏó¶¨ÒåÒ»¸öÊôÐÔ
this.f1="this is f1";
}
//2£©ÎÒÃÇ¿ÉÒÔÕâÑùʹÓöÔÏó£º
var a = new A();
alert(a.f1)//µ¯³öÏûÏ¢£ºthis is f1
//3£©ÎÒÃÇ¿ÉÒÔÀ©Õ¹¶ÔÏó£º
A.prototype.f1 = "this is new f1";
A.prototype.f2 = "this is f2";
//4£©¼ÌÐøÊ¹ÓöÔÏó£º
alert(a.f1)//µ¯³öÏûÏ¢£ºthis is f1¡¾²»ÊÇthis is new f1¡¿
alert(a.f2)//µ¯³öÏûÏ¢£ºthis is f2
˵Ã÷£ºµ±ÎÒÃÇʹÓöÔÏóʱ£¬Ê×ÏÈ´Ó¶ÔÏóµÄ¶¨ÒåÖÐÈ¥ÕÒ¶ÔÓ¦µÄÊôÐÔ£¬ÕÒ²»µ½ÔÙ´ÓprototypeÖÐÈ¥ÕÒ¡£
Èç4£©Öе÷ÓÃa.f1£¬¾ÍÄÜ´Ó¶ÔÏó±¾Éí¶¨ÒåÖÐÕÒµ½f1ÊôÐÔ£¬²»»áÔÙÈ¥prototypeÖÐÈ¥ÕÒf1ÊôÐÔ£¬ËùÒÔÀ©Õ¹µÄf1ÊôÐÔ¾ÍÓò»ÉÏÁË
¶øa.f2£¬ÔòÒòΪÔÚ¶ÔÏó±¾Éí¶¨ÒåÖÐûÓÐÕÒµ½f2ÊôÐÔ£¬ÄÇôҪ¼ÌÐø´ÓprototypeÖÐѰÕÒÓÐûÓÐf2µÄ¶¨Ò壬ÕÒµ½¾Í·µ»ØËü
Ïà¹ØÎĵµ£º
//×Ô´øµÄ´òÓ¡Ô¤ÀÀ WebBrowser.ExecWB(1,1) ´ò¿ª
Web.ExecWB(2,1) ¹Ø±ÕÏÖÔÚËùÓеÄIE´°¿Ú£¬²¢´ò¿ªÒ»¸öд°¿Ú
Web.ExecWB(4,1) ±£´æÍøÒ³
Web.ExecWB(6,1) ´òÓ¡
Web.ExecWB(7,1) ´òÓ¡Ô¤ÀÀ
Web.ExecWB(8,1) ´òÓ¡Ò³ÃæÉèÖÃ
Web.ExecWB(10,1) ²é¿´Ò ......
//УÑéÊÇ·ñÈ«ÓÉÊý×Ö×é³É
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//УÑéµÇ¼Ãû£ºÖ»ÄÜÊäÈë5-20¸öÒÔ×Öĸ¿ªÍ·¡¢¿É´øÊý×Ö¡¢“_”¡¢“.”µÄ×Ö´®
function isRegisterUserName(s)
{
v ......
to make a note that I love JavaScript. This article is only meant for some fun, and for us to be aware of some its short-comings.
1. The Name. JavaScript is NOT Java
We'll start with a fun jab at the name choice. While it was originally called Mocha, and then LiveScript, it was later changed to J ......
<script language="JavaScript">
<!--
//ͼƬ°´±ÈÀýËõ·Å
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//²ÎÊý(ͼƬ,ÔÊÐíµÄ¿í¶È,ÔÊÐíµÄ¸ß¶È)
var image=new Image();
image.src=ImgD.src; ......