Nomad & His Life

          博觀而約取,厚積而薄發
          posts - 15, comments - 88, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          公告

          歡迎訪問:http://www.jialing.net
          Q我!

          積分與排名

          • 積分 - 38450
          • 排名 - 1199

          最新評論

          《Learn JavaScript in a Weekend》導讀+筆記

          Posted on 2006-08-03 12:56 Nomad 閱讀(706) 評論(1)  編輯  收藏 所屬分類: 原版閱讀

          o_159200086X_140_34O.gif

          這是一本JavaScript的入門書籍。作者用通俗易懂的語言講述JavaScript的基本內容,由書名就能看得出來,讀者只需要一個周末就能將它看完。書的最后兩章順帶介紹了微軟的JScript和WSH。可以在http://www.cnshare.org 上下載。

          星期五晚上:"Introducing JavaScript and JScript."
          介紹了JavaScript和JScript的歷史知識和基本情況。

          星期六早晨:"Learning the Basics of JavaScript Coding."
          講解JavaScript的基本語法、函數、數組,以及基于對象的特性。

          星期六中午:"Using JavaScript to Build Better Web Pages."
          詳細描述了JavaScript對象的特性。首先介紹了Browser里的document、form、location等特殊類,然后介紹如何編寫自己的對象,最后介紹如何處理Frames和表單。

          星期六晚上:"Doing Really Cool Things with Your Web Pages."
          介紹了一些特別的東西。比如如何控制狀態欄,如何控制瀏覽器,展示各種不同的彈出窗口,讓JavaScript工作在不同的瀏覽器中,用JavaScript制作的動畫。

          星期天早晨:"Advanced JavaScript Coding."
          JavaScript高級編程。首先介紹的是cookie操作,然后是寫JavaScript的一些經驗,最后用了很大的篇幅介紹一個在線書店的制作。

          星期天中午: "Learning How to Use JScript and the WSH."
          略。

          星期天晚上: "Using JScript to Automate Windows Tasks."
          略。



          方法

          for in循環

          用來遍歷一個特殊對象的全部屬性。

          for (variable in object) {

          ? statements;

          }

          每次循環這個object的一個屬性就被設為variable

          ?

          示例:

          <HTML>

          ? <HEAD>

          ??? <TITLE>Script 2.18 - Demonstration of the for in statement

          </TITLE>

          ? </HEAD>

          ? <BODY>

          ??? <SCRIPT LANGUAGE="JavaScript" TYPE="Text/JavaScript">

          ??? <!-- Start hiding JavaScript statements

          ?

          ????? for (i in navigator) {

          ????????? document.write(i,"<BR>");

          ????? }

          ?

          ??? // End hiding JavaScript statements -->

          ??? </SCRIPT>

          ? </BODY>

          </HTML>

          ?

          ?

          with 方法

          這是一個簡便的方法來執行對某個object的操作。

          with (object) {

          ? statements;

          }

          在括號里的語句可以執行object的方法,而不用多敲"object."。例如,將object換為document,在statements中只要寫write(...),就相當于document.write(...)

          ?

          示例:

          <HTML>

          ? <HEAD>

          ??? <TITLE>Script 2.19 - Demonstration of the with statement

          </TITLE>

          ? </HEAD>

          ? <BODY>

          ??? <SCRIPT LANGUAGE="JavaScript" TYPE="Text/JavaScript">

          ??? <!-- Start hiding JavaScript statements

          ?

          ????? with (document) {

          ??????? write("The with statement saved me a few keystrokes.

          <BR>");

          ??????? write("Its use is purely discretionary!");

          ????? }

          ?

          ??? // End hiding JavaScript statements -->

          ??? </SCRIPT>

          ? </BODY>

          </HTML>

          當然,這個方法除了省去你一些敲鍵盤的時間外,沒有其他的功能。

          ?

          ?

          ?

          ?

          ?

          ?

          數組

          ?

          排序數組

          數組里有sort()方法來排序它的內容,直接看示例:

          <HEAD>

          ? <TITLE>Script 2.25 - Sorting an Array</TITLE>

          </HEAD>

          ? <BODY>

          ??? <SCRIPT LANGUAGE="JavaScript" TYPE="Text/JavaScript">

          ??? <!-- Start hiding JavaScript statements

          ?

          ????? Animals = new Array("mice", "dog", "cat", "hamster", "fish");

          ?

          ????? document.write("<B>List of animals in the Zoo</B><BR>");

          ????? document.write(Animals.sort());? // 輸出cat,dog,fish,hamster,mice

          ?

          ??? // End hiding JavaScript statements -->

          ??? </SCRIPT>

          ? </BODY>

          </HTML>

          ?

          ?

          ?

          ?

          對象

          ?

          Function 對象

          JavaScript 同意你創建Function對象。對于一般的方法并不適用。這樣可以讓你更好的組織你的方法,但是由于Function對象固有的效率問題,最好少用。

          語法:FunctionName = new Function([p1,.......pn] body)

          示例:Warn = new Function("alert('HI!')");

          ?

          ?

          Math 對象

          下面列出了Math對象的一些屬性和方法。

          Table 2.5. SUMMARY OF MATH PROPERTIES

          Property

          Description

          E

          Euler's constant (2.718)

          LN2

          Natural logarithm of 2 (2.302)

          LN10

          Natural logarithm of 10 (.693)

          LOG2E

          Base 2 logarithm of e (.434)

          LOG10

          Base 10 logarithm of 10 (1.442)

          PI

          Ratio of the circumference of a circle to its diameter (3.141549)

          SQRT1_2

          Square root of ? (.707)

          SQRT2

          Square root of 2 (1.414)

          ?

          Table 2.6. SUMMARY OF MATH METHODS

          Method

          Description

          abs()

          Returns the absolute value

          cos(), sin(), tan()

          Trigonometric functions

          acos(), asin(), atan()

          Inverse trigonometric functions

          exp(), log()

          Exponential and natural logarithms

          ceil()

          Returns the lowest integer greater than or equal to the argument

          floor()

          Returns the highest integer less than or equal to the argument

          min(x,y)

          Returns either x or y, depending on which is lower

          max(x,y)

          Returns either x or y, depending on which is higher

          pow(x,y)

          Returns the value of x y

          random()

          Returns a random number between 0 and 1

          round()

          Rounds the argument to the nearest integer

          sqrt()

          Returns the square of the argument

          ?

          ?

          ?

          Object 對象

          Object 對象是所有對象的基礎。

          MyNumberObject = new Object(99.99);

          MyStringObject = new Object("Testing");

          ?

          ?

          ?

          String 對象

          下面列出了String對象的常用方法。

          Table 2.8. COMMLY USED STRING OBJECT METHODS

          Method

          Description

          charAt()

          Returns the character at the specified position in the string where the index of a String object begins at zero

          concat()

          Combines two strings into one new string

          fromCharCode()

          Creates a string value based on the supplied code set

          indexOf()

          Returns the position of a specified substring

          lastIndexOf()

          Returns the last position of a specified substring

          slice()

          Creates a new string using a portion of the current string

          split()

          Organizes a string into an array

          substring()

          Returns the specified portion of a string

          toLowerCase()

          Returns the string in all lowercase characters

          toUppercase()

          Returns the string in all uppercase characters

          ?

          ?

          ?

          ?

          ?

          瀏覽器對象

          window 對象

          關于窗口的操作

          window.alert()

          window.close()

          window.forward()

          window.back()

          window.home()

          window.resizeTo(300,400)

          ?

          ?

          document 對象

          最常用的對象!

          _???????? anchors[]. An array containing a list of all anchors in the document

          _???????? applets[]. An array containing a list of all applets in the document

          _???????? embeds[]. An array containing a list of all embedded objects in the document

          _???????? forms[]. An array containing a list of all forms in the document

          _???????? images[]. An array containing a list of all images in the document

          _???????? links[]. An array containing a list of all links in the document

          _???????? plugins[]. An array containing a list of all plug-ins in the document

          Other document object properties enable you to affect appearance:

          _???????? bgColor. Specifies the document background color

          _???????? fgColor. Specifies the color of document text

          _???????? linkColor. Specifies the color of links

          _???????? alinkColor. Specifies the color of active links

          _???????? vlinkColor. Specifies the color of visited links

          Here is a partial list of other useful document properties:

          _???????? cookie. Lets you get and set cookie values

          _???????? lastModified. A string that shows the date and time at which the document was last changed

          _???????? referrer. A string showing the URL the user came from

          _???????? title. A string containing the contents of the HTML <TITLE> tags

          _???????? URL. A string containing the document's URL

          ?

          ?

          ?

          ?

          ?

          高效程序員的習慣

          ?

          寫大量的注釋。

          ?

          注意縮距讓你的代碼易讀。

          ?

          盡量將代碼模塊化。

          ?

          在腳本的頂端聲明方法和變量。

          ?

          以一致的方式命名你的變量和方法。

          ?

          用一致的語法命名變量和方法。

          ?

          不要僅運行了一次而認為你的代碼沒有bug

          ?

          用不支持JavaScript的瀏覽器運行你的代碼,讓你的腳本有一個正確的輸出。

          ?

          測試所有可能的場景。

          ?

          寫一點測試一點。

          ?

          以瀏覽器不同的大小來測試你頁面的輸出,保證它們都是你想要的。

          ?

          測試每個事件處理器。

          ?

          用變量的關鍵字明確的聲明變量。

          ?

          方法或變量名用描述性的語言,而不用單個字母。

          ?

          取對象名時小心系統已經定義的名字。

          ?

          注意引號里的字符。

          ?

          Remember to use plenty of comments. Comments enable you to explain why you wrote the script the way you did and to explain particularly difficult sections of code. Comments make it much easier for others to follow behind you and for you to understand your own code months or years later.

          ?

          Always use indentation to make your code easy to read. Indenting statements also makes it easier for you to match up beginning and ending tags, curly braces, and other HTML and script elements.

          ?

          Write modular code. Whenever possible, group your statements into functions. Functions let you group related statements, and test and reuse portions of code with minimal effort. Simplify your design by assigning only one task to a function.

          ?

          Declare functions and variables at the top of your scripts. This approach makes those elements easy to find and modify, and is a lot less confusing than embedding them throughout different portions of lengthy scripts. This technique also helps to ensure that the functions and variables are defined before they are referenced.

          ?

          Be consistent in the way you name variables and functions. Try using names that are long enough to be meaningful and that describe the contents of the variable or the purpose of the function.

          ?

          Use consistent syntax when naming variables and functions. In other words, keep them all lowercase or all uppercase; if you prefer Camel-Back notation, use it consistently.

          ?

          Do not assume that your script is bug free just because it ran once without an error. Make sure that you test the script using different browsers and, if possible, with different versions of the same browser.

          ?

          Make sure that you test your script using browsers that do not support JavaScript to ensure that your script properly provides alternative content. Try disabling support in your browsers for things such as frames to make sure that all browsers display your information as you intend it to be displayed.

          ?

          Test all possible scenarios. This includes testing with good and bad data. If your pages have forms, enter invalid data and check to make sure that the validation routines work as you think they will. Test every link and click on every button.

          ?

          Test long scripts in a modular fashion. In other words, do not try to write the entire script before testing any portion of it. Write a piece and get it to work before adding the next portion of code.

          ?

          Load your pages using different resolutions to make sure that they look as you expect them to at any size. Also try resizing your browser windows to see how your HTML pages look at different sizes.

          ?

          Test every event handler to ensure that it executes as expected.

          ?

          Declare variables explicitly using the var keyword.

          ?

          Use descriptive variable and function names and avoid using single-character names.

          ?

          Pay attention when using object names. Core JavaScript objects begin with capitalized letters (for example, Array, Boolean, Date, Function, Math, Number, Object, RegExp, and String).

          ?

          Watch your quotation marks. Remember that quotation marks are used in pairs around strings and that both quotation marks must be of the same style (either single or double). If you want to show quotation marks as part of the text message, embed them inside quotation marks of the alternate type (for example, place single quotation marks inside double quotation marks and vice versa).

          ?


          評論

          # re: 《Learn JavaScript in a Weekend》導讀+筆記  回復  更多評論   

          2006-08-10 19:27 by 坎井之蛙
          等發工資,去買。。。,呵呵!

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 乐平市| 阜城县| 阳信县| 建平县| 焉耆| 定结县| 九江县| 石柱| 衡东县| 阿克陶县| 卫辉市| 遂宁市| 乐业县| 开原市| 巴林左旗| 元谋县| 淳化县| 邯郸市| 尚义县| 泾阳县| 原阳县| 连云港市| 稷山县| 达日县| 新干县| 金秀| 大冶市| 东城区| 周口市| 麻阳| 丰县| 雅安市| 密云县| 牙克石市| 三台县| 蓬溪县| 仁布县| 吴忠市| 镇原县| 南涧| 共和县|