Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaScript ¼Ì³ÐÏê½â3

ÔÚµÚÒ»ÕÂÖУ¬ÎÒÃÇʹÓù¹Ô캯ÊýºÍÔ­Ð͵ķ½Ê½ÔÚJavaScriptµÄÊÀ½çÖÐʵÏÖÁËÀàºÍ¼Ì³Ð£¬ µ«ÊÇ´æÔںܶàÎÊÌâ¡£ÕâÒ»ÕÂÎÒÃǽ«»áÖðÒ»·ÖÎöÕâЩÎÊÌ⣬²¢¸ø³ö½â¾ö·½°¸¡£
×¢£º±¾ÕÂÖеÄjClassµÄʵÏֲο¼ÁËSimple JavaScript Inheritance
µÄ×ö·¨¡£
Ê×ÏÈÈÃÎÒÃÇÀ´»Ø¹ËһϵÚÒ»ÕÂÖнéÉܵÄÀý×Ó£º
function Person(name) {
this.name = name;
}
Person.prototype = {
getName: function() {
return this.name;
}
}
function Employee(name, employeeID) {
this.name = name;
this.employeeID = employeeID;
}
Employee.prototype = new Person();
Employee.prototype.getEmployeeID = function() {
return this.employeeID;
};
var zhang = new Employee("ZhangSan", "1234");
console.log(zhang.getName()); // "ZhangSan"
ÐÞÕýconstructorµÄÖ¸Ïò´íÎó
´ÓÉÏһƪÎÄÕÂÖйØÓÚconstructorµÄÃèÊö£¬ÎÒÃÇÖªµÀEmployeeʵÀýµÄconstructor»áÓÐÒ»¸öÖ¸Ïò´íÎó£¬ÈçÏÂËùʾ£º
var zhang = new Employee("ZhangSan", "1234");
console.log(zhang.constructor === Employee); // false
console.log(zhang.constructor === Object); // true
ÎÒÃÇÐèÒª¼òµ¥µÄÐÞÕý£º
function Employee(name, employeeID) {
this.name = name;
this.employeeID = employeeID;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.prototype.getEmployeeID = function() {
return this.employeeID;
};
var zhang = new Employee("ZhangSan", "1234");
console.log(zhang.constructor === Employee); // true
console.log(zhang.constructor === Object); // false
´´½¨EmployeeÀàʱʵÀý»¯PersonÊDz»ºÏÊʵÄ
µ«ÁíÒ»·½Ã棬ÎÒÃÇÓÖ±ØÐëÒÀÀµÓÚÕâÖÖ»úÖÆÀ´ÊµÏּ̳С£ ½â¾ö°ì·¨ÊDz»ÔÚ¹¹Ô캯ÊýÖгõʼ»¯Êý¾Ý£¬¶øÊÇÌṩһ¸öÔ­ÐÍ·½·¨£¨±ÈÈçinit£©À´³õʼ»¯Êý¾Ý¡£
// ¿ÕµÄ¹¹Ô캯Êý
function Person() {
}
Person.prototype = {
init: function(name) {
this.name = name;
},
getName: function() {
return this.name;
}
}
// ¿ÕµÄ¹¹Ô캯Êý
function Employee() {
}
// ´´½¨ÀàµÄ½×¶Î²»»á³õʼ»¯¸¸ÀàµÄÊý¾Ý£¬ÒòΪPersonÊÇÒ»¸ö¿ÕµÄ¹¹Ô캯Êý
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.prototyp


Ïà¹ØÎĵµ£º

JavascriptÖÐ×î³£ÓõÄ55¸ö¾­µä¼¼ÇÉ

1. oncontextm ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectst> È¡ÏûÑ¡È¡¡¢·ÀÖ¹¸´ÖÆ
3.  ²»×¼Õ³Ìù
4.   ·ÀÖ¹¸´ÖÆ
5. <link  > IEµØÖ·À¸Ç°»»³É×Ô¼ºµÄͼ±ê
6. <link   ......

javascript ÃæÏò¶ÔÏó±à³ÌµÄÆðµã

/*
* JavaScript¶ÔÏó¾ÍÊÇÒ»×éÊôÐÔ£¨·½·¨£©µÄ¼¯ºÏ
* ÔÚ¸ÃÓïÑÔÖÐÈç¹û±äÁ¿Ãû»ò·½·¨Ãû²»·ûºÏÉùÃ÷¹æ·¶£¬
* ÔòÒ»¶¨µÃÓ÷½À¨ºÅ“ [] ”ÒýÓÃËü
*
*/


/**
* <1.>¸ÃÓï¾äÉùÃ÷ÁËÒ»¸öclass1À࣬class1Ï൱ÓÚ¹¹Ôì·½·¨£¬Óֽй¹ÔìÆ÷
* Ò²¿É˵ÉùÃ÷ÁËÒ»¸öclass1·½·¨
......

javascriptÖÐreplaceÕýÔò±í´ïʽÓï·¨

replace()×î¼òµ¥µÄËãÊÇÄÜÁ¦¾ÍÊǼòµ¥µÄ×Ö·ûÌæ»»¡£
  ʾÀý´úÂëÈçÏ£º
<script language="javascript">
var strM = "javascript is a good script language";
//ÔÚ´ËÎÒÏ뽫×ÖĸaÌæ»»³É×ÖĸA
alert(strM.replace("a","A"));
</script>
ËüÖ»Ìæ»»ÁËÊ××Öĸ¡£µ«Èç ......

javascript»ñÈ¡ä¯ÀÀÆ÷µÄ¿í¶ÈºÍ¸ß¶È

<script language="JavaScript" type="text/JavaScript">
<!--
        function displayScreenSize()
        {
            var bodyWidth      ......

JavaScriptÌØÐÔ×ܽá

1.js²»Ö§³ÖÖØÔØ£¬ÒòΪjsÀïµÄº¯Êý¶¼ÊÇÒ»¸ö¶ÔÏó£¬jsÀïÓиöÒþº¬¶ÔÏóFunction,ËùÓеÄjsº¯Êý¶¼ÊÇÒ»¸öFunctionÀàÐ͵ĶÔÏó¡£±ÈÈ磺
Java´úÂë
function add(number)   
{   
   alert("hello");   
}  
function add(number)
{
alert("hello");
}
µÈ¼ÛÓ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ