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
Ïà¹ØÎĵµ£º
1. oncontextm ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectst> È¡ÏûÑ¡È¡¡¢·ÀÖ¹¸´ÖÆ
3. ²»×¼Õ³Ìù
4. ·ÀÖ¹¸´ÖÆ
5. <link > IEµØÖ·À¸Ç°»»³É×Ô¼ºµÄͼ±ê
6. <link   ......
/*
* JavaScript¶ÔÏó¾ÍÊÇÒ»×éÊôÐÔ£¨·½·¨£©µÄ¼¯ºÏ
* ÔÚ¸ÃÓïÑÔÖÐÈç¹û±äÁ¿Ãû»ò·½·¨Ãû²»·ûºÏÉùÃ÷¹æ·¶£¬
* ÔòÒ»¶¨µÃÓ÷½À¨ºÅ“ [] ”ÒýÓÃËü
*
*/
/**
* <1.>¸ÃÓï¾äÉùÃ÷ÁËÒ»¸öclass1À࣬class1Ï൱ÓÚ¹¹Ôì·½·¨£¬Óֽй¹ÔìÆ÷
* Ò²¿É˵ÉùÃ÷ÁËÒ»¸öclass1·½·¨
......
replace()×î¼òµ¥µÄËãÊÇÄÜÁ¦¾ÍÊǼòµ¥µÄ×Ö·ûÌæ»»¡£
ʾÀý´úÂëÈçÏ£º
<script language="javascript">
var strM = "javascript is a good script language";
//ÔÚ´ËÎÒÏ뽫×ÖĸaÌæ»»³É×ÖĸA
alert(strM.replace("a","A"));
</script>
ËüÖ»Ìæ»»ÁËÊ××Öĸ¡£µ«Èç ......
<script language="JavaScript" type="text/JavaScript">
<!--
function displayScreenSize()
{
var bodyWidth ......
1.js²»Ö§³ÖÖØÔØ£¬ÒòΪjsÀïµÄº¯Êý¶¼ÊÇÒ»¸ö¶ÔÏó£¬jsÀïÓиöÒþº¬¶ÔÏóFunction,ËùÓеÄjsº¯Êý¶¼ÊÇÒ»¸öFunctionÀàÐ͵ĶÔÏó¡£±ÈÈ磺
Java´úÂë
function add(number)
{
alert("hello");
}
function add(number)
{
alert("hello");
}
µÈ¼ÛÓ ......