Javascript¼Ì³Ð»úÖÆ£¨call¡¢apply¡¢prototype£©
JavascriptµÄ¼Ì³Ð¿ÉÒÔͨ¹ýcall¡¢apply¡¢prototypeʵÏÖ¡£
1¡¢call£ºÔÚ×ÓÀàÖУ¬Óø¸Àà.call£¨this£¬arg0£¬arg1...£©¿ÉÒԼ̳и¸Àà¡£×¢ÒâcallµÄλÖ㬾¡Á¿ÔÚ×ÓÀàµÄµÚÒ»ÐУ¨js°´Ë³ÐòÖ´ÐУ¬·ÅÔÚºóÃæ¿ÉÄܶÔ×ÓÀàµÄÆäËûÊôÐÔ¡¢·½·¨ÓÐÓ°Ïì¡£±ÈÈç×ÓÀàºÍ¸¸ÀàÓÐÏàͬÃû×ֵķ½·¨£¬ºóÃæµÄ¸²¸ÇÇ°ÃæµÄ£©¡£
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//personÀà
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//studentÀ࣬¼Ì³Ð×Ôperson
function student(name, age, no) {
person.call(this, name, age);//personÖеÄthisµÈÓÚ²ÎÊýÖеÄthis£¬¼´studentÖеÄnameºÍage
this.no = no;
this.display = function() {//¸²¸ÇÁ˸¸ÀàµÄ·½·¨
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//´´½¨personÀà
var p = new person("captain", 21);
p.display();//captain-21
p.say();//I am a person
//´´½¨studentÀà
var s = new student("captain", 21, "06281097")
s.display();//captain-21-06281097
s.say();//I am a person ¼Ì³ÐÁ˸¸ÀàµÄ·½·¨
<script>
<body>
</body>
</html>
2¡¢apply£ºÔÚ×ÓÀàÖУ¬Óø¸Àà.apply£¨this£¬args£©¿ÉÒԼ̳и¸ÀࣨargsΪ²ÎÊýÊý×飩¡£
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//personÀà
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//studentÀ࣬¼Ì³Ð×Ôperson
function student(name, age, no) {
person.apply(this, new Array(name, age));//Óëcall²»Í¬µÄÊÇ£¬apply´«µÝµÄÊÇÊý×é
this.no = no;
this.display = function() {//¸²¸ÇÁ˸¸ÀàµÄ·½·¨
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//´´½¨pe
Ïà¹ØÎĵµ£º
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JSµ÷ÓÃÏÖ³ÉWordÄ£°åÍê³É´òÓ¡</title>
<script type="text/javascript">
//ת»»wordµÄº¯Êý
function ......
<script language=JAVAscript>
var s="b";
var strCode
for(var i=0;i<s.length;i++)
{
strCode=s.charCodeAt(i);
if((strCode>65248)||(strCode==12288))
{
alert("ÓÐÈ«½Ç");
break;
}
}
</script>
°ë½Ç×Ö·ûÓÉÒ»¸ö×Ö½Ú±£´æ£¬È«½Ç×Ö·ûÓÃÁ½¸ö×Ö½Ú±£´æ
ËùÒÔÂëÖµµÄ¾ø¶ÔֵСÓÚ256µÄ¾ÍÊǰë½Ç£¬· ......
½ñÌìÒªÏò´ó¼ÒÍÆ¼ö9¿îºÜ°ôµÄ¿ÉÔÚÍøÒ³ÖлæÖÆÍ¼±íµÄJavaScript½Å±¾£¬ÕâЩÓÐȤµÄJS½Å±¾¿ÉÒÔ°ïÖúÄã¿ìËÙ·½±ãµÄ»æÖÆÍ¼±í£¨Ïß¡¢Ãæ¡¢±ý¡¢Ìõ…£©£¬ÆäÖаüÀ¨jQuery¡¢MooTools¡¢PrototypeºÍһЩÆäËüµÄJavaScript¿ò¼Ü¡£
Äú»¹¿ÉÒԲο¼ÒÔÏÂJavaScript/CSSÏà¹Ø½Ì³Ì¼°×ÊÔ´:
¡¶¾«Ñ¡30¸öÓÅÐãµÄCSS¼¼Ê ......
http://xiayuanfeng.javaeye.com/blog/£¨ÔÎÄ£©
ʲôÊǺ¯Êý(Function)
function sum(a,b){
return a+b;
}
ÆäʵͨË×µÄ˵¾ÍÊÇÒ»¸öÓÐÃû³ÆµÄ´úÂë¶Î£¬·½±ãÖØÓá£
ҪעÒâµÄÊÇ£º
1.Javascript µÄº¯ÊýÓï·¨£¬ÒòΪJavascript±¾Éí¾ÍÊÇÇø·Ö´óСдµÄ£¬ËùÒÔfunction²»ÄÜд×÷Function»ò ......
Several programming languages implement a sprintf function, to output a formatted string. It originated from the C programming language, printf function. Its a string manipulation function.
This is limited sprintf Javascript implementation. Function returns a string formatted by the usual printf co ......