RSS   



  可打印版本 | 推薦給朋友 | 訂閱主題 | 收藏主題 | 純文字版  


 


 
主題: [問題] 請問一下 javascript 和 Tomcat 的問題   字型大小:||| 
jocosn
白銀驢友
等級: 15等級: 15等級: 15等級: 15等級: 15


今日心情

 . 積分: 1386
 . 精華: 2
 . 文章: 2945
 . 收花: 9537 支
 . 送花: 3671 支
 . 比例: 0.38
 . 在線: 1295 小時
 . 瀏覽: 19041 頁
 . 註冊: 7251
 . 失蹤: 1254
#1 : 2005-8-3 04:55 AM     只看本作者 引言回覆

想請問各位 Javascript 的問題,紅色字是我的疑問:

測試環境 IE6 + Win2003,
我遇到的問題是,最近看一本 Mcgraw-Hill 的 Javascript 2.0 -The complete reference 第 2 版的書,寫到 object literal,查了一下網頁

car = { manyCars: {a: "Saab", b: "Jeep"}, 3: "Mazda" } ;
document.write(car.manyCars.a);       // Jeep
document.write(car[3]);      // Mazda
連結點
http://www.croczilla.com/~alex/r ... /ident.html#1009450


這個例子以前看也沒問題,但是這次我改了一下

car = { manyCars: {1: "Saab", 2: "Jeep"}, 3: "Mazda" } ;
document.write(car.manyCars.2);      // error:必須要有 ')'
document.write(car[3]);     // Mazda
寫成 car.manyCars.2 會有錯誤,須改成這樣 car.manyCars[2]
我又試 car[3] 改成 car.3 也是不行

於是我想到是不是 identifier 名稱問題,開頭不能使用阿拉伯數字命名,但是這樣應該 car = { manyCars: {1: "Saab", 2: "Jeep"}, 3: "Mazda" } ; 這行就會出現錯誤,為什麼瀏覽器沒有顯示?於是我又改了程式碼:

car = { manyCars: {a: "Saab", 2a: "Jeep"}, 3: "Mazda" } ;     // error:必須要有 ':'
document.write(car.manyCars.a);
document.write(car[3]);     // Mazda
用 firefox 1.0.6 版,錯誤箭頭指在 2a 的 a 下面
錯誤: missing : after property id
原始碼:
car = { manyCars: {a: "Saab", 2a: "Jeep"}, 3: "Mazda" } ;
                ↑

最後結論就是

car = { a: "Jeep", 3: "Mazda" } ;
可以這樣用 car[a]  或 car.a
但是只能這樣用 car[3],不能這樣用 car.3   
事實上,可能這種命名有錯誤,但是 browser 是大笨蛋,因為 3 改成 3j 這種混合"阿拉伯數字+英文字"就會出現錯誤
所以 objectName.propertyName = objectName.["propertyName"] 這 2 個在某些情況下不通用(property 名稱是純阿拉伯數字時)。這種錯誤是 javascript 或是 browser 的 bug 嗎?
照理講,如果不能用 car.3,那應該就連這個 3 名稱本身就錯誤才合理。可以宣告,但是不能使用 . 引用;或是可以宣告 3 ,但是 3a 就會錯誤,怪怪?


-------------------------------------------------
另外一個問題

function Pet(pet_type, pet_sound, pet_transport_mode){
    this.type = pet_type;
    this.sound = pet_sound;
    this.transport_mode = pet_transport_mode;
}
 
function displayProperties() {
    document.write("My pet is a "+ this.type +"<br>");
    document.write("My pet says "+ this.sound +"<br>");
    document.write("My pet can "+ this.transport_mode +"<br>");
}

var myPet = new Pet("cat", "meow", "walk");  
// Create a new property
myPet.display = displayProperties;  
myPet.display();  // Invoke the method,顯示結果 A →行X
myPet.display("cat1", "meow2", "walk3");    // 顯示結果 B
"顯示結果 A" 同 "顯示結果 B",2 者都顯示:

My pet is a cat
My pet says meow
My pet can walk
看起來 () 接參數不起作用,於是我把 "行X" 的 myPet.display(); 改成 myPet.display; ,螢幕一片空白,沒有顯示任何東西!

或改成

myPet.display = displayProperties();
myPet.display;

顯示結果:
My pet is a undefined
My pet says undefined
My pet can undefined
變成 () 一定要接在 myPet.display(); 這行,但是 () 是一個垃圾,寫好看而已,不能接參數。
如果 () 沒用,為什麼不精簡的寫成下面程式碼?


myPet.display = displayProperties;
myPet.display;  // 不須加 () ,因為根本不接受參數傳入
我一直覺的,Javascript 感覺就像 VB。語法亂一通。
----------------------------------------------------------------
另外一個是 Java 問題
我看了一篇文章提到 Server 和 Client 的 JVM,蔡學鏞的一段文章:
以往 J2SE 同時會附上 Server 和 Client 的 JVM(更早的 JVM 還會多附上 Classic JVM),但是 Java 5.0 以後,J2SE 只附上 Client 的 JVM(jre\bin\client\jvm.dll),沒有附上 Server 的 JVM(jre\bin\server\jvm.dll)。想要具有 Server 的 JVM,必須安裝 J2EE 才行。
http://www.microsoft.com/taiwan/msdn/columns/DoNet/NETCLR.htm

我查了一下
-------------
They are essentially two different compilers (JITs) interfacing to the same runtime system. The client system is optimal for applications which need fast startup times or small footprints, the server system is optimial for applications where the performance is most important. In general the client system is better on GUIs. Some of the other differences include the compilation policy used, heap defaults, and inlining policy.

http://alpha-geek.com/2004/06/16 ... s_in_java_benchmark

文章提到,主要是一個講速度,一個講效能。
蔡 sir 說需要安裝 J2EE,才會附上 Server 版的 JVM (我查了一下,他講的應該是 windows\java 目錄下的 JVM,非 JDK 下的 JVM)。


我剛發現一種情況:
我使用 Windows2003 + Tomcat 5.5,啟動 Configure Tomcat 後發現

因 Tomcat 安裝時會要你指定 jre 目錄,由上圖中得知 C:\Program Files\Java\jre1.5.0_04\bin\client\jvm.dll ,Tomcat 是跑 client 的 jvm !!!!

像這種情況,如果公司使用 Windows2003 架 Server,應該再灌 SDK,然後使用 SDK/jre/bin/server/jvm.dll 比較好是嗎?
如果只安裝 JRE 這種東西,是沒有 server 版的 jvm.dll ,這樣跑 Tomcat 可能就不太好是嗎?
但是一般來講,server 不是都不安裝 SDK?只裝 jre?


[jocosn 在 2005-8-3 05:13 AM 作了最後編輯]



[如果你喜歡本文章,就按本文章之鮮花~送花給作者吧,你的支持就是別人的動力來源]
本文連接  
檢閱個人資料  發私人訊息  Blog  快速回覆 新增/修改 爬文標記
musicsun
未開啟帳號


今日心情

 . 積分: 141
 . 文章: 569
 . 收花: 680 支
 . 送花: 304 支
 . 比例: 0.45
 . 在線: 583 小時
 . 瀏覽: 811 頁
 . 註冊: 8009
 . 失蹤: 4
#2 : 2005-8-3 09:54 AM     只看本作者 引言回覆

1.
javascript不熟,以一般程式語言來說...
變數名稱要英文字母開頭,數字不能當變數但可以當陣列Index
car = { manyCars: {a: "Saab", b: "Jeep"}, 3: "Mazda" } ;   這樣的宣告應該是一種混用

2.
myPet.display = displayProperties; 是個定義,displayProperties是函式名,所以myPet.display也是函式名,或者是看成函式指標的指定敘述
myPet.display = displayProperties(); 是執行displayProperties()把結果存到myPet.display

displayProperties()沒有引數,所以myPet.display()也沒有引數,加了"()"才叫函式
myPet.display這個只是個變數,無法構成敘述

對於這敘述myPet.display("cat1", "meow2", "walk3");    我覺得應該會有警告訊息,或者語法錯誤

3.
不認識什麼湯姆貓

[musicsun 在 2005-8-3 09:57 AM 作了最後編輯]



[如果你喜歡本文章,就按本文章之鮮花~送花給作者吧,你的支持就是別人的動力來源]
本文連接  
檢閱個人資料  發私人訊息  Blog  快速回覆 新增/修改 爬文標記

   

快速回覆
表情符號

更多 Smilies

字型大小 : |||      [完成後可按 Ctrl+Enter 發佈]        

溫馨提示:本區開放遊客瀏覽。
選項:
關閉 URL 識別    關閉 表情符號    關閉 Discuz! 代碼    使用個人簽名    接收新回覆信件通知
發表時自動複製內容   [立即複製] (IE only)


 



所在時區為 GMT+8, 現在時間是 2024-5-5 03:36 AM
清除 Cookies - 連絡我們 - TWed2k © 2001-2046 - 純文字版 - 說明
Discuz! 0.1 | Processed in 0.022529 second(s), 6 queries , Qzip disabled