JavaScriptÀàºÍ¼Ì³Ð£ºconstructorÊôÐÔ
constructorÊôÐÔʼÖÕÖ¸Ïò´´½¨µ±Ç°¶ÔÏóµÄ¹¹Ô캯Êý¡£±ÈÈçÏÂÃæÀý×Ó£º
// µÈ¼ÛÓÚ var foo = new Array(1, 56, 34, 12);
var arr = [
1
,
56
,
34
,
12
];
console.log(arr.constructor === Array);
// true
// µÈ¼ÛÓÚ var foo = new Function();
var Foo = function() { };
console.log(Foo.constructor === Function);
// true
// Óɹ¹Ô캯ÊýʵÀý»¯Ò»¸öobj¶ÔÏó
var obj =
new
Foo();
console.log(obj.constructor === Foo);
// true
// ½«ÉÏÃæÁ½¶Î´úÂëºÏÆðÀ´£¬¾ÍµÃµ½ÏÂÃæµÄ½áÂÛ
console.log(obj.constructor.constructor === Function);
// true
µ«Êǵ±constructorÓöµ½prototypeʱ£¬ÓÐȤµÄÊÂÇé¾Í·¢ÉúÁË¡£
ÎÒÃÇÖªµÀÿ¸öº¯Êý¶¼ÓÐÒ»¸öĬÈϵÄÊôÐÔprototype£¬¶øÕâ¸öprototypeµÄconstructorĬÈÏÖ¸ÏòÕâ¸öº¯Êý¡£ÈçÏÂÀýËùʾ£º
function Person(name) {
this
.name = name;
};
Person.prototype.getName = function() {
return
this
.name;
};
var p =
new
Person(
"ZhangSan"
);
console.log(p.constructor === Person);
// true
console.log(Person.prototype.constructor === Person);
// true
// ½«ÉÏÁ½ÐдúÂëºÏ²¢¾ÍµÃµ½ÈçϽá¹û
console.log(p.constructor.prototype.constructor === Person);
// true
µ±Ê±µ±ÎÒÃÇÖØÐ¶¨Ò庯ÊýµÄprototypeʱ£¨×¢Ò⣺ºÍÉÏÀýµÄÇø±ð£¬ÕâÀï²»ÊÇÐ޸ĶøÊǸ²¸Ç£©£¬constructorÊôÐÔµÄÐÐΪ¾ÍÓÐµãÆæ¹ÖÁË£¬Èç
ÏÂʾÀý£º
function Person(name) {
this
.name = name;
};
Person.prototype = {
 
Ïà¹ØÎĵµ£º
Ò»£¬javascriptÖеĶÔÏó
¡£¶ÔÏóºÍ¶ÔÏóʵÀý
1£¬¶ÔÏóÊǶÔijһÀàÊÂÎïµÄÃèÊö£¬ÊdzéÏóÉϵĸÅÄ¶ø¶ÔÏóʵÀýÊÇÒ»ÀàÊÂÎïÖеľßÌå¸öÀý¡££¨ÕâÀï¶ÔÏóÏ൱ÓÚjava£¬c++ÖеÄÀàµÄ¸ÅÄ
2£¬Äܹ»±»ÓÃÀ´´´½¨¶ÔÏóʵÀýµÄº¯Êý¾Í½Ð×ö¶ÔÏóµÄ¹¹Ô캯Êý£¬Ö»Òª¶¨ÒåÁËÒ»¸ö¶ÔÏóµÄ¹¹Ô캯Êý¾ÍµÈÓÚ¶¨ÒåÁËÒ»¸ö¶ÔÏó£¬Ê¹ÓÃnew¹Ø¼ü×ֺͶÔÏóµÄ¹¹Ô캯Êý¾Í¿ÉÒÔ ......
confirm(string) ·½·¨
1¡¢ÓÐÒ»¸östringÀàÐͲÎÊý£¬ËüµÄÖµ¾ÍÊÇÔÚ¶Ô»°¿òÖеÄÎı¾ÐÅÏ¢¡£
2¡¢boolean ÀàÐ͵ķµ»ØÖµ¡£Ñ¡Ôñ“È·¶¨”·µ»ØµÄ¾ÍÊÇtrue,Ñ¡Ôñ“È¡Ïû”·µ»Øfalse¡£
¾ÙÀý£º
<script type="text/javascript">
function cfm() {
i ......
JavascriptÖеij£¼ûÎÊÌâ
1. ¼¯ºÏÀà¶ÔÏóÎÊÌâ
ÏÖÓдúÂëÖÐÐí¶à¼¯ºÏÀà¶ÔÏóÈ¡ÓÃʱʹÓà ()£¬IE ÄܽÓÊÜ£¬Firefox ²»ÄÜ¡£
½â¾ö·½·¨£º¸ÄÓà [] ×÷ΪϱêÔËËã¡£È磺document.forms("formName") ¸ÄΪ
Js´úÂë
document.forms[
"formName"
];
//ÓÖÈ磺
document.getEle ......
Ò»£¬javascriptµÄÄÚ²¿¶ÔÏó£¨Ï൱ÓÚϵͳµ÷Óã¬Æäʵ±¾ÖÊÊÇÒ»¸ö¹¹Ô캯Êý£©
1£¬¶¯Ì¬¶ÔÏó
ʹÓÓ¶ÔÏóʵÀýÃû.³ÉÔ±”µÄ¸ñʽÀ´·ÃÎÊÆäÊôÐԺͷ½·¨¡££¨ÓÃnewÏÈ´´½¨¶ÔÏóʵÀý£©
2£¬¾²Ì¬¶ÔÏó
Ö±½ÓʹÓÓ¶ÔÏóÃû.³ÉÔ±”µÄ¸ñʽÀ´·ÃÎÊÆäÊôÐԺͷ½·¨
¶þ£¬¼¸¸öÄÚÖö ......
ÃæÏò¶ÔÏóµÄ
JavaScript
ÒýÓã¨
reference
£©
“ÒýÓÔÊÇÒ»¸öÖ¸Ïò¶ÔÏóʵ¼ÊλÖõÄÖ¸Õë¡£ÕâÊÇÒ»¸ö¼«ÎªÇ¿´óµÄÌØÐÔ£¬µ«ÓÐÒ»¸öǰÌ᣺ʵ¼ÊµÄ¶ÔÏó¿Ï¶¨²»»áÊÇÒýÓá£×Ö·û´®ÓÀÔ¶ÊÇ×Ö·û´®£¬Êý×éÓÀÔ¶ÊÇÊý×é¡£²»¹ý¶à¸ö±äÁ¿È´Äܹ»Ö¸Ïòͬһ¶ÔÏó¡£
JavaScript
»ùÓڵľÍÊÇÕâÑùÒ»¸öÒýÓÃϵͳ¡£
ÕâÃÅÓïÑÔͨ¹ýά»¤Ò»Ïµ ......