Ô´ÂëÍø,Ô´ÂëÂÛ̳,Ô´ÂëÖ®¼Ò,ÉÌÒµÔ´Âë,ÓÎÏ·Ô´ÂëÏÂÔØ,discuz²å¼þ,ÆåÅÆÔ´ÂëÏÂÔØ,¾«Æ·Ô´ÂëÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
Â¥Ö÷: ttx9n

[JavaScript] javascriptÃæÏò¶ÔÏóÖ®¶þ ÃüÃû¿Õ¼ä

[¸´ÖÆÁ´½Ó]

7Íò

Ö÷Ìâ

861

»ØÌû

32Íò

»ý·Ö

ÂÛ̳ԪÀÏ

Rank: 8Rank: 8

»ý·Ö
329525
·¢±íÓÚ 2011-2-8 23:09:38 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ
javascriptÖб¾Ã»ÓÐÃüÃû¿Õ¼äµÄ¸ÅÄµ«ÊÇÒªÌåÏÖÃæÏò¶ÔÏóµÄ˼Ï룬Ӧµ±ÓÐÃüÃû¿Õ¼ä£¬¾ÍÏñjavaÖеÄpackage£¬.netÖеÄnamespaceÒ»Ñù£¬×÷ÓÃÖ÷ҪΪÁË·ÀÖ¹ÀàÃû³åÍ»£¬ÏàͬµÄÀàÃûÖ»ÒªÊôÓÚ²»Í¬µÄÃüÃû¿Õ¼ä£¬±ã²»»á³åÍ»¡£ ×î¼òµ¥´´½¨ÃüÃû¿Õ¼äµÄ·½·¨£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
var java = {};
java.util = {};
//ÕâÑù¾Í´´½¨³É¹¦ÁËÃüÃû¿Õ¼ä£ºjava.util
//ÎÒÃÇ¿ÉÒÔÔÚjava.utilÏÂÃæ¼ÓÀà(º¯Êý),ÊôÐÔ£¬»ò¶ÔÏó
java.util.HashMap = function()
{
this.ShowMessage = function()
{
alert("java.util.HashMap");
}
}
var map = new java.util.HashMap();
alert(map.ShowMessage()); //ÏÔʾ½á¹û£ºjava.util.HashMap

//·â×°´´½¨ÃüÃû¿Õ¼äµÄ·½·¨£º
//¶¨ÒåÒ»¸ö¶ÔÏó£¬jsÖÐÓÃ{}»¨À¨ºÅ¶¨Òå¶ÔÏ󣬵ÈͬÓÚ var JsObject = new Object();¡¡¡¡
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
var JsObject = {};
JsObject.namespace = function() //ÔÚJsObject¶ÔÏó϶¨ÒåÒ»¸öº¯Êýnamespace
{
¡¡/*ÏÂÃæ´úÂëÖÐargumentsΪº¯Êý´«ÈëµÄ²ÎÊý£¬ÔÚfunctionδÃ÷È·¶¨Òå²ÎÊýʱ£¬
¡¡¡¡functionÒ²¿ÉÒÔ´«Èë²ÎÊý£¬²¢ÓÃargumentsÀ´ ½ÓÊÕ£¬argumentsÀàËÆÊý×飬
¡¡¡¡Èç¹û´«Èë¶à¸ö²ÎÊý£¬½«°´Ë³Ðò±£´æ£¬È¡Öµ·¨£ºarguments[0],arguments[1]....*/
var a = arguments,o = null,d,rt;
for(var i = 0; i < a.length; i++)
{
d = a[i].split('.'); //½«´«ÈëµÄ²ÎÊýÓ÷ûºÅ'.' ½øÐзָ²¢·ÅÈëdÊý×éÖС£
rt = d[0];
//ÅжÏÊý×éÖеĵÚÒ»¸öÖµÊÇ·ñ䶨Ò壬Èç¹û䶨Ò壬±ã¶¨ÒåΪ¿Õ¶ÔÏó{},²¢¸³Öµ¸ø±äÁ¿o
eval('if (typeof ' + rt + ' == "undefined"){'
¡¡¡¡¡¡¡¡¡¡¡¡+ rt + ' = {};} o = ' + rt + ';');
¡¡¡¡for(var j = 1; j < d.length; j++)
¡¡¡¡{
¡¡¡¡¡¡¡¡/*Ñ­»·±éÀúÊý×édÿ¸öÖµ×÷Ϊkey£¬¼ÓÈëµ½¶ÔÏóoÖУ¬Èç¹ûkeyÔÚoÖдæÔÚ£¬ÔòÈ¡oÖÐÖµ£¬Èô
¡¡¡¡¡¡¡¡²»´æÔÚ£¬Ôò¸³ÖµÎª¿Õ¶ÔÏó{} */ ¡¡¡¡
¡¡¡¡¡¡¡¡o[d[j]] = o[d[j]] || {};
¡¡¡¡¡¡ o = o[d[j]];
¡¡¡¡}
}
}
JsObject.namespace("org.myJs"); //ÉêÃ÷ÃüÃû¿Õ¼ä£ºorg.myJs
org.myJs.Student = function() //ÔÚÃüÃû¿Õ¼äorg.myJs϶¨ÒåÀàStudent
{
¡¡¡¡¡¡¡¡//¶¨ÒåÀàStudentÖеıäÁ¿£¬²¢¸³Óè³õÖµ£¬µ«´Ë±äÁ¿µÄ·ÃÎÊȨÏÞÊÇpublic
this.studentNo = 's001';
this.studentName = 'СÃ÷';
this.sex = 'ÄÐ';
}
var s = new org.myJs.Student(); //´´½¨StudentÀàµÄ¶ÔÏó
alert('ѧºÅ£º'+s.studentNo);
alert('ÐÕÃû£º'+s.studentName);
alert('ÐÔ±ð£º'+s.sex);

Ч¹ûºÍµÚһƪ (Ò»)javascript¾­Ñé×ܽáÃæÏò¶ÔÏó¡ªÀà ½á¹ûÒ»Ñù
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

0

Ö÷Ìâ

2Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2022-8-8 13:40:50 | ÏÔʾȫ²¿Â¥²ã
Êý¾Ý¿âÁ˶à¾ÃÈö¿ìÀֵĽ¡Éí¿¨À²

2

Ö÷Ìâ

2Íò

»ØÌû

69

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
69
·¢±íÓÚ 2022-8-10 21:16:44 | ÏÔʾȫ²¿Â¥²ã
¼Ó¿ìËٶȺܿì¾ÍÈö»Ñ

4

Ö÷Ìâ

2Íò

»ØÌû

58

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
58
·¢±íÓÚ 2022-12-16 08:41:32 | ÏÔʾȫ²¿Â¥²ã
¹Ü¹à¹à¹à¹à¹à¹à¹à¹à¹à¹à

0

Ö÷Ìâ

2Íò

»ØÌû

66

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
66
·¢±íÓÚ 2023-1-7 11:36:29 | ÏÔʾȫ²¿Â¥²ã
»¹ÓÐÈËÔÚ²»¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£°¡

14

Ö÷Ìâ

1Íò

»ØÌû

75

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
75
·¢±íÓÚ 2023-1-19 21:26:45 | ÏÔʾȫ²¿Â¥²ã
ÁËÀÖȤÁËÈ¥ÁËÈ¥ÁËÈ¥ÁËÈ¥ÁË

14

Ö÷Ìâ

1Íò

»ØÌû

75

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
75
·¢±íÓÚ 2023-1-28 12:40:43 | ÏÔʾȫ²¿Â¥²ã
iiguuubhuiuihu

0

Ö÷Ìâ

1Íò

»ØÌû

100

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
100
·¢±íÓÚ 2023-7-7 21:04:04 | ÏÔʾȫ²¿Â¥²ã
´ó¼Ò¶¼²»ÈÝÒ×£¡

1

Ö÷Ìâ

1Íò

»ØÌû

51

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
51
·¢±íÓÚ 2023-8-22 12:04:00 | ÏÔʾȫ²¿Â¥²ã
ºÜ²»´íµÄÔ´ÂëÂÛ̳

6

Ö÷Ìâ

2Íò

»ØÌû

247

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
247
·¢±íÓÚ 2023-8-31 17:06:41 | ÏÔʾȫ²¿Â¥²ã
»¹ÓÐʲôºÃ¶«Î÷û
¸ß¼¶Ä£Ê½
B Color Image Link Quote Code Smilies

±¾°æ»ý·Ö¹æÔò

ÊÖ»ú°æ|СºÚÎÝ|ÍøÕ¾µØͼ|Ô´ÂëÂÛ̳ ( º£Íâ°æ )

GMT+8, 2024-11-28 17:48 , Processed in 0.067710 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí