<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-15881528</id><updated>2011-12-15T15:37:07.236+13:00</updated><title type='text'>Sheldon's Smile</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jinsh2.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jinsh2.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>jinsh2</name><uri>http://www.blogger.com/profile/03008969182513984433</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-15881528.post-5359970788422071058</id><published>2007-01-07T01:19:00.000+13:00</published><updated>2007-01-07T01:39:14.743+13:00</updated><title type='text'></title><content type='html'>&lt;h1 style="color: rgb(204, 153, 51);"&gt;CakePHP 应用程序的数据流小结 · &lt;span style="font-size:85%;"&gt;Summary of Data Flow in CakePHP Web Application&lt;/span&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;1. Controllers fetch data in database through Models, and set to vars which are available in Views.&lt;br /&gt;1. Controllers(控制类) 通过 Models(模型类) 取得数据库的数据, 并赋给 Views 中能看到的变量。&lt;br /&gt;&lt;br /&gt;2. Controllers accept data from Webpages through vars such as 'params'.&lt;br /&gt;2. Controllers(控制类) 使用变量如 'params', 接受网页的数据。&lt;br /&gt;&lt;br /&gt;3. Data in Sessions would be handled by Session vars.&lt;br /&gt;3. 会话(Session)中的数据有专门的会话变量来处理。&lt;br /&gt;&lt;br /&gt;4. Views call renderElement() to display repeatable Element files (i.e. mini-views) and pass parameters.&lt;br /&gt;4. Views(视图类) 调用 renderElement() 来显示可重复用的 Element(元素) 文件 (即: 迷你视图) 并传递参数。&lt;br /&gt;&lt;br /&gt;5. render() is automatically called at the end of each controller action to render its View. But redirect() and flash() is used for redirection.&lt;br /&gt;5. 控制类的每个动作结束时能自动调用 render() 来递送 Views。而 redirect() 和 flash() 可用来转向。&lt;br /&gt;&lt;br /&gt;6. There are many special functions and variables in Controllers.&lt;br /&gt;6. 控制类中还有一些专门的函数和变量。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15881528-5359970788422071058?l=jinsh2.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinsh2.blogspot.com/feeds/5359970788422071058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15881528&amp;postID=5359970788422071058' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/5359970788422071058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/5359970788422071058'/><link rel='alternate' type='text/html' href='http://jinsh2.blogspot.com/2007/01/cakephp-summary-of-data-flow-in-cakephp.html' title=''/><author><name>jinsh2</name><uri>http://www.blogger.com/profile/03008969182513984433</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15881528.post-38510322248843692</id><published>2006-12-17T00:36:00.000+13:00</published><updated>2006-12-20T05:00:15.066+13:00</updated><title type='text'></title><content type='html'>&lt;h1 style="color: rgb(204, 153, 51);" class="title" align="center"&gt;A Survey of the JavaScript Programming Language&lt;/h1&gt;&lt;br /&gt;&lt;p class="center" align="center"&gt;&lt;a href="mailto:douglas@crockford.com"&gt;Douglas Crockford&lt;/a&gt; &lt;span class="cn"&gt;重点翻译: Sheldon 于 2006 春&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.crockford.com/" target="_top"&gt;www.crockford.com&lt;/a&gt;&lt;/p&gt;&lt;p class="center" align="center"&gt;© 2002 Douglas Crockford&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Overview&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;This document is an introduction to the &lt;a href="http://www.crockford.com/javascript"&gt;JavaScript Programming Language&lt;/a&gt; for professional programmers. It is a small language, so if you are familiar with other languages, then this won't be too demanding.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;JavaScript is not Java. They are two very different  languages. JavaScript is not a subset of Java. It is not interpreted Java. (Java is interpreted Java!) JavaScript shares C-family syntax with Java, but at a deeper level it shows greater similarity to the languages &lt;a href="http://javascript.crockford.com/little.html"&gt;Scheme&lt;/a&gt; and &lt;a href="http://research.sun.com/self/language.html"&gt;Self&lt;/a&gt; &lt;span class="cn"&gt;JavaScript 与 Java 共享 C 语言家族的语法, 但从更深的层次来说它的语法更像 Scheme 和 Self (译者注: 虽然是重点翻译, 但已翻出原文的全部重要点, 且仅仅读中文部分, 意思也连贯, 读者如有 C 和 Java 的基础, 通过本文应该能快速上手 JavaScript)&lt;/span&gt;. It is a small language, but it is also a suprisingly powerful and expressive language.You should take a look at it. You will find that it is not a toy language, but a full programming language with many distinctive properties.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;JavaScript  is a regular language which won't take much time to learn. It is better suited to some tasks, such as  client programming, than Java is &lt;span class="cn"&gt;JavaScript 比 Java 更适合去完成某些事，比如客户端编程&lt;/span&gt;. In my own practice, I have found that working with JavaScript has made me a better Java programmer because it introduced me to a useful set of dynamic techniques.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;When JavaScript was first introduced, I dismissed it as being not worth my attention. Much later, I took another look at it and discovered that hidden in the browser  was an excellent programming language. My initial attitudes were based on the initial positioning of JavaScript by Sun and Netscape. They made many misstatements about JavaScript in order to avoid positioning JavaScript as a competitor to Java. Those misstatements continue to echo in the scores of badly written JavaScript books aimed at the  dummies and amateurs market.&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;History&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://java.sun.com/pr/1995/12/pr951204-03.html"&gt;JavaScript&lt;/a&gt; was developed by Brendan Eich at &lt;a href="http://www.netscape.com/"&gt;Netscape&lt;/a&gt; as the in-page scripting language for &lt;a href="http://wp.netscape.com/security/bugbounty.html"&gt;Navigator 2&lt;/a&gt;. It is a remarkably expressive dynamic programming language. Because of its linkage to web browsers, it instantly became massively popular. It never got a trial period in which it could be corrected and polished based on actual use. The language is powerful and flawed.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This document describes ECMAScript Edition 3 (aka JavaScript 1.5). Microsoft and Netscape are developing a static revision which does not correct the language's flaws. That new language is not JavaScript &lt;span class="cn"&gt;译者注：好像是 JavaScript 2.0 还没出来，是基于类&lt;span style="font-size:60;"&gt;类型&lt;/span&gt;(class-based)的，而不像现在这样是基于原型(&lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Class-Based_vs._Prototype-Based_Languages#Class-Based_vs._Prototype-Based_Languages"&gt;prototype-based&lt;/a&gt;)的 OO 语言&lt;/span&gt; and  is beyond the scope of this document.&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Data Types&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;JavaScript contains a small set of data types. It has the three primitive types &lt;i&gt;boolean&lt;/i&gt;, &lt;i&gt;number&lt;/i&gt;, and &lt;i&gt;string&lt;/i&gt;  and the special values &lt;tt&gt;null&lt;/tt&gt; and &lt;tt&gt;undefined&lt;/tt&gt; &lt;span class="cn"&gt;有三个&lt;span class="cn"&gt;(译者注：非对象)&lt;/span&gt;基本类型 &lt;i&gt;boolean&lt;/i&gt;, &lt;i&gt;number&lt;/i&gt;, and &lt;i&gt;string&lt;/i&gt; 与特殊值 &lt;tt&gt;null (空/无效)&lt;/tt&gt; 和 &lt;tt&gt;undefined (无定义)&lt;/tt&gt;&lt;/span&gt;. Everything else is variations on the &lt;i&gt;object&lt;/i&gt; type &lt;span class="cn"&gt;其它都是 &lt;i&gt;object (对象)&lt;/i&gt; (译者注：&lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object#Summary"&gt;基本&lt;/a&gt;)类型的变化形式&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Boolean has two values: &lt;tt&gt;true&lt;/tt&gt; and &lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Number is 64-bit floating point &lt;span class="cn"&gt;number 是 64 位的浮点数&lt;/span&gt;, similar to Java's &lt;tt&gt;double&lt;/tt&gt; and &lt;tt&gt;Double&lt;/tt&gt;. There is no integer type &lt;span class="cn"&gt;没有 interger 类型&lt;/span&gt;.  Division between two integers may produce a fractional result. Number also includes the special values &lt;tt&gt;NaN&lt;/tt&gt; (not a number) and &lt;tt&gt;Infinity&lt;/tt&gt; &lt;span class="cn"&gt;number 型还包括特殊值 &lt;tt&gt;NaN (无定义数值)&lt;/tt&gt; 和 &lt;tt&gt;Infinity (无穷大)&lt;/tt&gt;&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;String is a sequence of zero or more Unicode characters. There is no separate character type &lt;span class="cn"&gt;没有单独的字符类型&lt;/span&gt;. A character is represented as a string of length 1. Literal strings are quoted using the&lt;tt&gt; ' &lt;/tt&gt;or&lt;tt&gt; " &lt;/tt&gt; characters. The quote characters can be used interchangeably, but they have to match.&lt;/p&gt;&lt;br /&gt;&lt;pre class="js"&gt;'This is a string.'&lt;/pre&gt;&lt;br /&gt;&lt;pre class="js"&gt;"Isn't this a string? Yes!"&lt;/pre&gt;&lt;br /&gt;&lt;pre class="js"&gt;'A' // The character A&lt;/pre&gt;&lt;br /&gt;&lt;pre class="js"&gt;"" // An empty string&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Escapement is done with the &lt;tt&gt;\&lt;/tt&gt; character, like in Java. Strings are immutable. Strings have a &lt;tt&gt;length&lt;/tt&gt; member &lt;span class="cn"&gt;String 有个 &lt;tt&gt;length&lt;/tt&gt; 成员&lt;/span&gt; which is used to determine the number of characters in the string.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var s = "Hello World!";&lt;br /&gt;s.length == 12&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;span class="cn"&gt;译者注：三种简单类型像 Java 一样对应有三种包装对象。&lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:String#Description"&gt;简单类型的字符串能调用 String 对象的成员方法，因为 JavaScript 在这过程中自动生成一个临时 String 对象。&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;It is possible to  add methods to the simple types. So, for example, you can add an &lt;tt&gt;int()&lt;/tt&gt; method to all numbers, so that &lt;tt&gt;Math.PI.int()&lt;/tt&gt; produces &lt;tt&gt;3&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;An implementation may provide other types, such as Dates and Regular Expressions, but these are really just objects. Everything else is just objects. &lt;span class="cn"&gt;好像实现了一些类型如 Date 和正则表达式 (译者注：这里指 RegExp)，其实只是对象。其他也都只是对象。&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;h3 class="major"&gt;Objects &lt;span class="cn"&gt;译者注：JavaScript 的对象很有意思，不需要用 class 定义，因为是基于原型的，所有对象都是实例&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;JavaScript has very nice notational conveniences for manipulating hashtables. &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var myHashtable = {};&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This statement makes a new hashtable and assigns it to a new local variable &lt;span class="cn"&gt;上述语句新产生了一个哈希表对象并赋值给一个新的局部变量&lt;/span&gt;. JavaScript is loosely typed, so we don't use type names in declarations &lt;span class="cn"&gt;JavaScript 是松类型语言，所以声明变量时没使用类型名&lt;/span&gt;. We use subscript notation to add, replace, or retrieve elements in the hashtable &lt;span class="cn"&gt;我们用下标来添加替换访问哈希表元素&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;myHashtable["name"] = "Carl Hollywood";&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;There is also a dot notation which is a little more convenient.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;myHashtable.city = "Anytown";&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The dot notation can be used when the subscript is a string constant in the form of a legal identifier. Because of an error in the language definition, reserved words cannot be used in the dot notation, but they can be used in the subscript notation.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You can see that JavaScript's hashtable notation is very similar to Java's object and array notations. JavaScript takes this much farther: objects and hashtables are the same thing, so I could have written &lt;span class="cn"&gt;JavaScript 的哈希表表示法很像 Java 的对象和数组表示法。JavaScript 甚至更进一步，对象和哈希表是相同的东西，于是上面的语句可替换成&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var myHashtable = new Object();&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;and the result would have been exactly the same. &lt;span class="cn"  style="color:red;"&gt;译者注：上面(事实上是整个这一节)说明了一般 object 对象的两种产生方法&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;There is an enumeration capability built into the &lt;tt&gt;for&lt;/tt&gt; statement &lt;span class="cn"&gt;语句 &lt;tt&gt;for&lt;/tt&gt; 内置了枚举能力&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;for (var n in myHashtable) {&lt;br /&gt;document.writeln("&amp;lt;p&amp;gt;" + n + ": " + myHashtable[n] + "&amp;lt;/p&amp;gt;");&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The result will be &lt;span class="cn"&gt;结果是&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;p&amp;gt;name: Carl Hollywood&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;city: Anytown&amp;lt;/p&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;An object is a referenceable container of name/value pairs &lt;span class="cn"&gt;一个对象是一个可引用(译者注：传值还是传引用，与 Java 处理相同。)的容器，内有一对对 名/值 对&lt;/span&gt;. The names are strings &lt;span class="cn"&gt;其名是字符串(或数值索引)&lt;/span&gt; (or other elements such as numbers that are converted to strings). The values can be any of the data types, including other objects. Objects are usually implemented as hash-tables, but none of the hash-table nature (such as hash functions or rehashing methods) is visible.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Objects can easily be nested inside of other objects, and expressions can reach into the inner objects.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;this.div = document.body.children[document.body.children.length - 1];&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In the object literal notation, an object description is a set of comma-separated name/value pairs inside curly braces &lt;span class="cn"&gt;一个字面对象的描述是花括弧以及在花括弧内一对对用逗号分开的名/值对&lt;/span&gt;. The names can be identifiers or strings followed by a colon &lt;span class="cn"&gt;冒号&lt;/span&gt;.  Because of an error in the language definition, reserved words cannot be used in the identifier form, but they can be used in the string form. The values can be literals or expressions of any type.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var myObject = {name: "Jack B. Nimble", 'goto': 'Jail', grade: 'A', level: 3};&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;return { //&lt;span class="cn"&gt;译者注：这里是新产生一个(匿名)对象，在函数定义中供返回&lt;/span&gt;&lt;br /&gt;event: event,&lt;br /&gt;op: event.type,&lt;br /&gt;to: event.srcElement,&lt;br /&gt;x: event.clientX + document.body.scrollLeft,&lt;br /&gt;y: event.clientY + document.body.scrollTop&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;emptyObject = {};&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;New members can be added to any object at any time by&lt;br /&gt;assignment &lt;span class="cn"&gt;新的成员在任何时候可通过赋值添加进任何对象&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;myObject.nickname = 'Jackie the Bee';&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Arrays and functions are implemented as objects &lt;span class="cn"&gt;数组和函数都实现为对象&lt;/span&gt;. &lt;span class="cn"&gt;译者注：函数是对象有点让人吃惊, 如果只知道命令式语言而不知道函数式语言的话。&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;h3 class="major"&gt;Arrays&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Arrays in JavaScript are also hashtable objects. This makes them very well suited to sparse array applications. When you construct an array, you do not need to declare a size &lt;span class="cn"&gt;不需要声明数组大小&lt;/span&gt;. Arrays grow automatically, much like Java vectors. The values are located by a key, not by an offset &lt;span class="cn"&gt;分量值通过键而不是偏移量来确定&lt;/span&gt;. This makes JavaScript arrays very convenient to use, but not well suited for applications in numerical analysis.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The main difference between objects and arrays is the &lt;tt&gt;length&lt;/tt&gt; property &lt;span class="cn"&gt;数组和一般对象最大的不同是有一个 &lt;tt&gt;length&lt;/tt&gt; 属性&lt;/span&gt;. The &lt;tt&gt;length&lt;/tt&gt; property is always 1 larger than the largest integer key in the array &lt;span class="cn"&gt;且其值总是比其数组最大的整数键的值大 1&lt;/span&gt;. There are two ways to make a new array &lt;span class="cn"&gt;有两种方法产生新数组&lt;/span&gt;:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var myArray = [];&lt;br /&gt;var myArray = new Array();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Arrays are not typed &lt;span class="cn"&gt;数组没类型（译者注：暂且先理解成"元素不要求相同类型"）&lt;/span&gt;. They can contain numbers, strings, booleans, objects, functions, and arrays. You can mix strings and numbers and objects in the same array &lt;span class="cn"&gt;同一个数组内可混合字符串，数，对象&lt;/span&gt;. You can use arrays as general nested sequences, much as s-expressions. The first index in an array is usually zero.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;When a new item is added to an array and the subscript is an integer that is larger than the current value of &lt;tt&gt;length&lt;/tt&gt;, then the &lt;tt&gt;length&lt;/tt&gt; is changed to the subscript plus one &lt;span class="cn"&gt;新加入的分量如果其下标整数值大于数组的 &lt;tt&gt;length&lt;/tt&gt; 数值，那么这 &lt;tt&gt;length&lt;/tt&gt; 值就变成那个下标值加 1&lt;/span&gt;. This is a convenience feature that makes it easy to use a &lt;tt&gt;for&lt;/tt&gt; loop to go through the elements of an array.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Arrays have a literal notation, similar to that for objects.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;myList = ['oats', 'peas', 'beans', 'barley'];&lt;br /&gt;&lt;br /&gt;emptyArray = [];&lt;br /&gt;&lt;br /&gt;month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];&lt;br /&gt;&lt;br /&gt;slides = [&lt;br /&gt;{url: 'slide0001.html', title: 'Looking Ahead'},&lt;br /&gt;{url: 'slide0008.html', title: 'Forecast'},&lt;br /&gt;{url: 'slide0021.html', title: 'Summary'}&lt;br /&gt;];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;A new item can be added to an array by assignment &lt;span class="cn"&gt;通过赋值，新分量可以添加进数组&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;a[i + j] = f(a[i], a[j]);&lt;/pre&gt;&lt;br /&gt;&lt;h1&gt;Functions&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;Functions in JavaScript look like C functions, except that they are declared with the &lt;tt&gt;function&lt;/tt&gt; keyword instead of a type &lt;span class="cn"&gt;但函数声明用关键字 &lt;tt&gt;function&lt;/tt&gt; 而没有类型&lt;/span&gt;. When calling a function &lt;span class="cn"&gt;函数调用时&lt;/span&gt;, it is not required that you pass a fixed number of parameters. Excess parameters are ignored. Missing parameters are given the value &lt;tt&gt;undefined&lt;/tt&gt; &lt;span class="cn"&gt;多余的参数会被忽略，而参数不够就设为(无定义) &lt;tt&gt;undefined&lt;/tt&gt;&lt;/span&gt;. This makes it easy to write functions that deal with optional arguments.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;A function has access to an &lt;tt&gt;arguments&lt;/tt&gt; array. It contains all of the parameters that were actually sent by the caller. It makes it easy to deal with functions taking a variable number of arguments. For example,&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;function sum() {  // Take any number of parameters and return the sum&lt;br /&gt;&lt;span class="cn"&gt;// 取不定多的参数并返回其和&lt;/span&gt;&lt;br /&gt;var total = 0;&lt;br /&gt;for (var i = 0; i &amp;lt; arguments.length; ++i) {&lt;br /&gt;  total += arguments[i];&lt;br /&gt;}&lt;br /&gt;return total;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;JavaScript has inner functions, which serve the same purpose as inner classes in Java, but are much lighter &lt;span class="cn"&gt;JavaScript 有内部函数，作用相当于 Java 的内部类，但更轻巧&lt;/span&gt;. JavaScript also has anonymous functions, which act as lambda expressions &lt;span class="cn"&gt;JavaScript 还有匿名函数可用作 lambda 表达式&lt;/span&gt;. Functions have lexical scoping. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Functions are first class objects in JavaScript &lt;span class="cn"&gt;函数在 JavaScript 中是顶级/头等对象&lt;/span&gt;. That means that they can be stored in objects and  passed as arguments to functions.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Definition&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;There are three notations for defining functions &lt;span class="cn"&gt;定义函数有三种表示法&lt;/span&gt;: function statement, function operator, and function constructor.&lt;/p&gt;&lt;br /&gt;&lt;h4&gt;Function statement&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;The function statement creates a named function within the current scope.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;tt&gt;function &lt;/tt&gt;&lt;i&gt;name&lt;/i&gt;&lt;tt&gt;(&lt;/tt&gt;&lt;i&gt;argumentlist&lt;/i&gt;&lt;tt&gt;)&lt;/tt&gt; &lt;i&gt;block&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Functions can be nested. See Closures. An &lt;i&gt;argumentlist&lt;/i&gt; is zero or more argument names, separated with commas. A &lt;i&gt;block&lt;/i&gt; is a list of zero or more statements enclosed in &lt;tt&gt;{ }&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The function statement is a shorthand for the function operator form &lt;span class="cn"&gt;函数语句/声明定义法是函数运算符/表达式定义法的简写&lt;/span&gt;: &lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;tt&gt;var &lt;/tt&gt;&lt;i&gt;name&lt;/i&gt;&lt;tt&gt; = function &lt;/tt&gt;&lt;i&gt;name&lt;/i&gt;&lt;tt&gt;(&lt;/tt&gt;&lt;i&gt;argumentlist&lt;/i&gt;&lt;tt&gt;) &lt;/tt&gt;&lt;i&gt;block&lt;/i&gt;&lt;tt&gt; ;&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&lt;span class="cn"&gt;译者注：跟据下面的说明，函数扩展成能在运算表达式中定义，函数声明式可以看成特例，即在上述表达式中函数名和一个变量名相同。一般可以是&lt;br /&gt;&lt;tt style="margin-left: 3em;"&gt;var &lt;i&gt;var_name&lt;/i&gt; = function &lt;i&gt;fun_name&lt;/i&gt;(&lt;i&gt;argumentlist&lt;/i&gt;) &lt;i&gt;block&lt;/i&gt; ;&lt;/tt&gt;&lt;br /&gt;(这同样说明函数也是对象)，&lt;i&gt;fun_name&lt;/i&gt; 只在函数体内可见，这不同于 &lt;i&gt;var_name&lt;/i&gt;。&lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions#Function_constructor_vs._function_declaration_vs._function_expression"&gt;参阅&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;h4&gt;Function operator&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;The function operator is a prefix operator that produces a function object &lt;span class="cn"&gt;这里 function 是个前缀运算符，(译者注：对参数作运算)产生函数对象&lt;/span&gt;. It looks similar to the function statement.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;tt&gt;function &lt;/tt&gt;&lt;i&gt;name&lt;/i&gt;&lt;tt&gt;(&lt;/tt&gt;&lt;i&gt;argumentlist&lt;/i&gt;&lt;tt&gt;)&lt;/tt&gt; &lt;i&gt;block&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The &lt;i&gt;name&lt;/i&gt; is optional &lt;span class="cn"&gt;这函数名 &lt;i&gt;name&lt;/i&gt; 可省略&lt;/span&gt;. If it is provided, then it can be used by the function body to call itself recursively. It can also be used to access the function's object members  (except on IE). If the name is omitted, then it is an anonymous function.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The function operator is commonly used to assign functions to a prototype.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The function operator can also be used to define functions in-place, which is handy when writing callbacks.&lt;/p&gt;&lt;br /&gt;&lt;h4&gt;Function constructor&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;The function constructor takes strings containing the arguments and body, and produces a function object.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;tt&gt;new Function(&lt;/tt&gt;&lt;i&gt;strings&lt;/i&gt;...&lt;tt&gt;)&lt;/tt&gt; &lt;span class="cn"&gt;/*译者注：注意大写 F */&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Do not use this form &lt;span class="cn"&gt;别用这种 Function 构造式定义法的形式&lt;/span&gt;. The quoting conventions of the language make it very difficult to correctly express a function body as a string. In the string form, early error checking cannot be done. It is slow because the compiler must be invoked every time the constructor is called. And it is wasteful of memory because each function requires its own independent implementation.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Objects and &lt;tt&gt;this&lt;/tt&gt; &lt;span class="cn"&gt;对象及 &lt;tt&gt;this&lt;/tt&gt;&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;A function is an object &lt;span class="cn"&gt;一个函数是一个对象&lt;/span&gt;. It can contain members just as other objects. This allows an function to contain its own data tables. It also allows an object to act as a &lt;i&gt;class&lt;/i&gt;, containing a constructor and a set of related methods &lt;span class="cn"&gt;也允许一个对象起类型的作用，包含一个构造式和一套相关的方法&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;A function can be a member of an object. When a function is a member of an object, it is called a &lt;i&gt;method&lt;/i&gt; &lt;span class="cn"&gt;函数成为对象的成员称为 &lt;i&gt;方法&lt;/i&gt;&lt;/span&gt;. There is a special variable, called &lt;tt&gt;this&lt;/tt&gt; that is set to the object when a method of the object is called.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;For example, in the expression &lt;tt&gt;foo.bar()&lt;/tt&gt;, the &lt;tt&gt; this&lt;/tt&gt; variable is set to the object &lt;tt&gt;foo&lt;/tt&gt; as a sort of extra argument for the function &lt;tt&gt;bar&lt;/tt&gt;. The function &lt;tt&gt;bar&lt;/tt&gt; can then refer to &lt;tt&gt;this&lt;/tt&gt; to access the object of interest.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In a deeper expression like &lt;tt&gt;do.re.mi.fa()&lt;/tt&gt;, the &lt;tt&gt;this&lt;/tt&gt; variable is set to the object &lt;tt&gt;do.re.mi&lt;/tt&gt;, not to the object &lt;tt&gt;do&lt;/tt&gt;. In a simple function call, &lt;tt&gt; this&lt;/tt&gt; is set to the Global Object (aka &lt;tt&gt;window&lt;/tt&gt;), which is not very useful.  The correct behavior should have been to preserve the current value of &lt;tt&gt;this&lt;/tt&gt;, particularly when calling inner functions.&lt;/p&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://developer.mozilla.org/wiki-images/en/8/8d/hier02.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: right; cursor: pointer; width: 320px;" src="http://developer.mozilla.org/wiki-images/en/8/8d/hier02.gif" alt="" border="0" /&gt;&lt;/a&gt;&lt;h3&gt;Constructor &lt;span class="cn"&gt;自己定义 对象的构造式&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Functions which are used to initialize objects are called &lt;i&gt;constructors&lt;/i&gt;. &lt;span class="cn"&gt;(译者&lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:The_Employee_Example:Creating_the_Hierarchy"&gt;网上找来一张图&lt;/a&gt;供参考说明构造式定义，以及在继承定义中的使用。)&lt;/span&gt; The calling sequence for a constructor is slightly different than for ordinary functions. A constructor is called with the &lt;tt&gt;new&lt;/tt&gt; prefix:&lt;/p&gt;&lt;br /&gt;&lt;blockquote style="clear: both;"&gt;  &lt;p&gt;&lt;tt&gt;new &lt;/tt&gt;&lt;i&gt;Constructor&lt;/i&gt;&lt;tt&gt;(&lt;/tt&gt;&lt;i&gt;parameters...&lt;/i&gt;&lt;tt&gt;)&lt;/tt&gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;By convention, the name of a constructor is written with an initial capital.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;new&lt;/tt&gt; prefix changes the meaning of the &lt;tt&gt;this&lt;/tt&gt; variable. Instead of its usual value, &lt;tt&gt;this&lt;/tt&gt; will be the new object. The body of the constructor function will usually initialize the object's members. The constructor will return the new object, unless explicitly overridden with the &lt;tt&gt;return&lt;/tt&gt;statement.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The constructed object will contain a secret prototype link field, which contains a reference to the constructor's &lt;tt&gt;prototype&lt;/tt&gt; member.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Prototype&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Objects contain a hidden link property. This link points to the &lt;tt&gt;prototype&lt;/tt&gt; member of the constructor of the object. &lt;span class="cn"&gt;对象含有一个隐藏链接属性，链接到构造式的 &lt;tt&gt;prototype (原型)&lt;/tt&gt; 成员。&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;When items are accessed from an object by the dot notation or the subscript notation, if the item is not found in the object then the link object is examined. If it is not found in the link object, and if the link object itself has a link object, then that link object is examined. If the chain of link objects is exhausted, then &lt;tt&gt;undefined&lt;/tt&gt; is returned.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This use of prototype link chains provides a sort of inheritance.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Members can be added to the &lt;tt&gt;prototype&lt;/tt&gt; by assignment. Here we define a new class &lt;tt&gt;Demo&lt;/tt&gt;, which inherits from class &lt;tt&gt;Ancestor&lt;/tt&gt;, and adds its own method &lt;tt&gt;foo&lt;/tt&gt; &lt;span class="cn"&gt;下面定义了一个新的"类" &lt;tt&gt;Demo&lt;/tt&gt;，(原型变成新的对象)继承于"类" &lt;tt&gt;Ancestor&lt;/tt&gt;，还 (译者注：用函数表达式定义法) 增加了成员方法 &lt;tt&gt;foo&lt;/tt&gt;&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;function Demo() {}&lt;br /&gt;Demo.prototype = new Ancestor();&lt;br /&gt;Demo.prototype.foo = function () {};&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Vars&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Named variables are defined with the &lt;tt&gt;var&lt;/tt&gt; statement. When used inside of a function, &lt;tt&gt;var&lt;/tt&gt; defines variables with &lt;i&gt;function-scope&lt;/i&gt;. The vars are not accessible from outside of the function. There is no other granularity of scope in JavaScript. In particular, there is no &lt;i&gt;block-scope&lt;/i&gt; &lt;span class="cn"&gt;特别是没有&lt;i&gt;块作用域&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Any variables used in a function which are not explicitly defined as &lt;tt&gt;var&lt;/tt&gt; are assumed to belong to an outer scope, possibly to the Global Object &lt;span class="cn"&gt;函数中没有用 &lt;tt&gt;var&lt;/tt&gt; 定义的变量属于外层作用域，甚至是全局根对象(Global Object)&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Vars which are not explicitly initialized are given the value &lt;tt&gt;undefined&lt;/tt&gt; &lt;span class="cn"&gt;没有明确初始化的变量值是 &lt;tt&gt;undefined&lt;/tt&gt;&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Vars are not typed. A var can contain a reference to an object, or a string or a number or a boolean or &lt;tt&gt;null&lt;/tt&gt; or &lt;tt&gt;undefined&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;A new set of vars is made every time the function is called. This allows functions to be recursive.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Closure &lt;span class="cn"&gt;闭包(译者注：嵌套的函数的局部变量及参数因为可见/作用域不同而形成的范围)&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Functions can be defined inside of other functions. The inner function has access to the vars and parameters of the outer function. If a reference to an inner function survives (for example, as a callback function), the outer function's vars also survive.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Return&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;JavaScript does not have a &lt;tt&gt;void&lt;/tt&gt; type, so every function must return a value. The default value is &lt;tt&gt;undefined&lt;/tt&gt;, except for constructors, where the default return value is &lt;tt&gt;this&lt;/tt&gt;. &lt;span class="cn"&gt;因为没有 &lt;tt&gt;void&lt;/tt&gt; 类型, 每个函数都有返回值，默认值是 &lt;tt&gt;undefined&lt;/tt&gt;，除了构造式的默认值是 &lt;tt&gt;this&lt;/tt&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Statements&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;The set of named statements includes &lt;tt&gt;var&lt;/tt&gt;, &lt;tt&gt;if&lt;/tt&gt;, &lt;tt&gt;switch&lt;/tt&gt;, &lt;tt&gt;for&lt;/tt&gt;, &lt;tt&gt;while&lt;/tt&gt;, &lt;tt&gt;do&lt;/tt&gt;, &lt;tt&gt;break&lt;/tt&gt;, &lt;tt&gt;continue&lt;/tt&gt;, &lt;tt&gt;return&lt;/tt&gt;, &lt;tt&gt;try&lt;/tt&gt;, &lt;tt&gt;throw&lt;/tt&gt;, and &lt;tt&gt;with&lt;/tt&gt;. Most of them work the same as in other C-like languages.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;var&lt;/tt&gt; statement is a list of one or more variables names, separated by commas, with optional initialization expressions.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var a, b = window.document.body;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;If the &lt;tt&gt;var&lt;/tt&gt; statement appears outside of any function, it adds members to the Global Object. If it appears inside of a function, it defines local variables of the function.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In &lt;tt&gt;if&lt;/tt&gt; statements, &lt;tt&gt;while&lt;/tt&gt; statements, &lt;tt&gt;do&lt;/tt&gt; statements, and logical operators, JavaScript treats &lt;tt&gt;false&lt;/tt&gt;, &lt;tt&gt;null&lt;/tt&gt;, &lt;tt&gt;undefined&lt;/tt&gt;, &lt;tt&gt;""&lt;/tt&gt; (the empty string), and the number &lt;tt&gt;0&lt;/tt&gt; as false &lt;span class="cn"&gt;JavaScript 对待 &lt;tt&gt;false&lt;/tt&gt;, &lt;tt&gt;null&lt;/tt&gt;, &lt;tt&gt;undefined&lt;/tt&gt;, &lt;tt&gt;""&lt;/tt&gt; (空字符串), 和数 &lt;tt&gt;0&lt;/tt&gt; 为 false&lt;/span&gt;. All other values are treated as &lt;tt&gt;true&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;case&lt;/tt&gt; labels in a &lt;tt&gt;switch&lt;/tt&gt; statement can be expressions. They don't have to be constants. They can be strings.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;There are two forms of the &lt;tt&gt;for&lt;/tt&gt; statement. The first is the common (init; test; inc) form. The second is an object iterator.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;for (name in object) {&lt;br /&gt;value = object[name];&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The block is executed for each &lt;tt&gt;name&lt;/tt&gt; in the &lt;tt&gt;object&lt;/tt&gt;. The order in which the names are produced is not guaranteed.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Statements can have a label prefix, which is an identifier followed with a colon.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;with&lt;/tt&gt; statement should not be used.&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Operators&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;JavaScript has a fairly large set of operators. Most of them work the same way as in other C-like languages. There are a few differences to watch out for.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;+&lt;/tt&gt; operator is used for both addition and concatenation. If either of the operands is a string, it concatenates. This can cause errors. For example, &lt;tt&gt;'$' + 3 + 4&lt;/tt&gt; produces &lt;tt&gt;'$34'&lt;/tt&gt;, not &lt;tt&gt;'$7'&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;tt&gt;+&lt;/tt&gt; can be used as a prefix operator, converting its string operand to a number.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;tt&gt;!!&lt;/tt&gt; can be used as a prefix operator, converting its operand to a boolean.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;&amp;&amp;amp;&lt;/tt&gt; operator is commonly called &lt;i&gt;logical and&lt;/i&gt;. It can also be called &lt;i&gt;guard&lt;/i&gt;. If the first operand is &lt;tt&gt;false&lt;/tt&gt;, &lt;tt&gt;null&lt;/tt&gt;,&lt;tt&gt;undefined&lt;/tt&gt;, &lt;tt&gt;""&lt;/tt&gt; (the empty string), or the number &lt;tt&gt;0&lt;/tt&gt; then it returns the first operand. Otherwise, it returns the second operand. This provides a convenient way to write a null-check:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;var value = p &amp;amp;amp;&amp; p.name; /* The name value will&lt;br /&gt;only be retrieved from p if p has a value, avoiding an error. */&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;||&lt;/tt&gt; operator is commonly called &lt;i&gt;logical or&lt;/i&gt;. It can also be called &lt;i&gt;default&lt;/i&gt;. If the first operand is &lt;tt&gt;false&lt;/tt&gt;, &lt;tt&gt;null&lt;/tt&gt;,&lt;tt&gt;undefined&lt;/tt&gt;, &lt;tt&gt;""&lt;/tt&gt; (the empty string), or the number &lt;tt&gt;0&lt;/tt&gt;, then it returns the second operand. Otherwise, it returns the first operand. This provides a convenient way to specify default values:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;value = v || 10; /* Use the value of v, but if v&lt;br /&gt;doesn't have a value, use 10 instead. */&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;JavaScript supplies a set of bitwise and shift operators, but does not have an Integer type to apply them to. What happens is the Number operand (a 64-bit floating-point number) is converted to a 32-bit integer before the operation, and then converted back to floating point after the operation.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In JavaScript, &lt;tt&gt;void&lt;/tt&gt; is a prefix operator, not a type. It always returns &lt;tt&gt;undefined&lt;/tt&gt;. This has very little value &lt;span class="cn"&gt;JavaScript 的 &lt;tt&gt;void&lt;/tt&gt; 是前缀运算符而不是类型，结果值是 &lt;tt&gt;undefined&lt;/tt&gt;，很少用&lt;/span&gt;. I only mention it in case you accidently type &lt;tt&gt;void&lt;/tt&gt; out of habit and are puzzled by the strange behavior.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;typeof&lt;/tt&gt; operator returns a string based on the type  of its operand.&lt;/p&gt;&lt;br /&gt;&lt;p class="warning"&gt;Mistakes were made.&lt;/p&gt;&lt;table&gt;  &lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;Object    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'object'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;Array    &lt;/td&gt;    &lt;td&gt;&lt;tt class="warning"&gt;'object'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;Function    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'function'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;String    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'string'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;Number    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'number'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;Boolean    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'boolean'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;&lt;tt&gt;null&lt;/tt&gt;    &lt;/td&gt;    &lt;td&gt;&lt;tt class="warning"&gt;'object'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;&lt;tt&gt;undefined&lt;/tt&gt;    &lt;/td&gt;    &lt;td&gt;&lt;tt&gt;'undefined'&lt;/tt&gt;    &lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;h1&gt;Potpourri&lt;/h1&gt;&lt;br /&gt;&lt;h3&gt;Global Object&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;The Global Object is the keeper of all of the functions and variables which were not defined inside of other functions and objects. Surprisingly, the Global Object does not have an explicit name in the language &lt;span class="cn"&gt;Global Object 没有显式的名字&lt;/span&gt;. Sometimes the &lt;tt&gt;this&lt;/tt&gt; variable points at it, but often not. In the web browsers, &lt;tt&gt;window&lt;/tt&gt; and &lt;tt&gt;self&lt;/tt&gt; are members of the Global Object which point to the Global Object &lt;span class="cn"&gt;Web 浏览器中用 Global Object 的成员 &lt;tt&gt;window&lt;/tt&gt; 和 &lt;tt&gt;self&lt;/tt&gt; 指向 Global Object&lt;/span&gt;, thus giving an indirect way of addressing it.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;If a variable is accessed, but is not found in the current scope, it is looked for in the Global Object. If it is not found there, an error will result.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The ECMAScript specification does not talk about the possibility of multiple Global Objects, or &lt;i&gt;contexts&lt;/i&gt;, but browsers support this &lt;span class="cn"&gt;ECMAScript 说明中没谈到多重 Global Object 或 Context 的可能性, 但浏览器有支持&lt;/span&gt;. Each window has its own Global Object &lt;span class="cn"&gt;每个窗口有自己的 Global Object&lt;/span&gt;.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Semicolon Insertion&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;One of the mistakes in the language is semicolon insertion. This is a technique for making semicolons optional as statement terminators. It is reasonable for IDEs and shell programs to do semicolon insertion. It is not reasonable for the language definition to require compilers to do it. Use semicolons.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Reserved Words&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;JavaScript is very heavy handed in its restrictions on reserved words. The reserved words are&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;tt&gt;abstract&lt;br /&gt;boolean &lt;b&gt;break&lt;/b&gt; byte&lt;br /&gt;&lt;b&gt;case&lt;/b&gt; &lt;b&gt;catch&lt;/b&gt; char class const &lt;b&gt;continue&lt;/b&gt;&lt;br /&gt;debugger &lt;b&gt;default&lt;/b&gt; &lt;b&gt;delete&lt;/b&gt; &lt;b&gt;do&lt;/b&gt; double&lt;br /&gt;&lt;b&gt;else&lt;/b&gt; enum export extends&lt;br /&gt;&lt;b&gt;false&lt;/b&gt; final &lt;b&gt;finally&lt;/b&gt; float &lt;b&gt;for&lt;/b&gt; &lt;b&gt;function&lt;/b&gt;&lt;br /&gt;goto&lt;br /&gt;&lt;b&gt;if&lt;/b&gt; implements import &lt;b&gt;in&lt;/b&gt; &lt;b&gt;instanceof&lt;/b&gt; int   interface&lt;br /&gt;long&lt;br /&gt;native &lt;b&gt;new null&lt;/b&gt;&lt;br /&gt;package private protected public&lt;br /&gt;&lt;b&gt;return&lt;/b&gt;&lt;br /&gt;short static super &lt;b&gt;switch&lt;/b&gt; synchronized&lt;br /&gt;&lt;b&gt;this&lt;/b&gt; &lt;b&gt;throw&lt;/b&gt; throws transient &lt;b&gt;true try&lt;/b&gt;   &lt;b&gt;typeof&lt;/b&gt;&lt;br /&gt;&lt;b&gt;var&lt;/b&gt; volatile &lt;b&gt;void&lt;/b&gt;&lt;br /&gt;&lt;b&gt;while&lt;/b&gt; &lt;b&gt;with&lt;/b&gt;&lt;/tt&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Most of those words are not even used in the language. A reserved word cannot be used&lt;/p&gt;&lt;ol&gt;  &lt;li&gt;As a name in literal object notation&lt;/li&gt;  &lt;li&gt;As a member name in dot notation&lt;/li&gt;  &lt;li&gt;As a function argument&lt;/li&gt;  &lt;li&gt;As a &lt;tt&gt;var&lt;/tt&gt;&lt;/li&gt;  &lt;li&gt;As an unqualified global variable&lt;/li&gt;  &lt;li&gt;As a statement label&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;There is no excuse for the first two restrictions. None. There is an excuse for the second two restrictions, but it is very weak.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15881528-38510322248843692?l=jinsh2.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinsh2.blogspot.com/feeds/38510322248843692/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15881528&amp;postID=38510322248843692' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/38510322248843692'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/38510322248843692'/><link rel='alternate' type='text/html' href='http://jinsh2.blogspot.com/2006/12/survey-of-javascript-programming.html' title=''/><author><name>jinsh2</name><uri>http://www.blogger.com/profile/03008969182513984433</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15881528.post-116423208852647892</id><published>2006-11-23T10:44:00.000+13:00</published><updated>2006-11-30T13:15:33.480+13:00</updated><title type='text'></title><content type='html'>&lt;h1&gt;&lt;span style="color:#cc9933;"&gt;软件中的英文翻译中文规则&lt;/span&gt;&lt;br&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#cc9933;"&gt;(Rules of Translation to Chinese)&lt;/span&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;目的:&lt;/strong&gt; 为了有高质量且统一的译文, 促进软件中文化。制定以下规则供参考。&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;要求:&lt;/strong&gt; 以 "信达雅" 的标准来衡量。 "信" 诚信可信, 不宜翻译的保持引用原文; "达" 达意通顺, 但不能为了通顺而违反原意不可信; "雅" 是文学标准。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;规则 1.&lt;/strong&gt; 尽量使用英文的格式和标点, 除了使用中文的句号(。)和英文的双引号(" ")。&lt;br /&gt;&lt;br /&gt;说明:&lt;br /&gt;&lt;br /&gt;英文和中文的标点符号大多数是相同的, 尽量保留原标点能省时省力, 更何况中文的标点本就是引进的。 但使用中文的句号代替英文的句号, (不用中文的双引号) 用英文的双引号代替英文的单引号。因为英文软件中, 点(period)(.)和单引号(')有很多不同的意思。&lt;br /&gt;&lt;br /&gt;例如: 文件名中的点号, 网址中的点号, 手册页(man page)中的格式是以点号起行, 等, 其实都是 dot。用中文的 "空心" 句号来断句有明显的优势。虽然有些科技文章用 "实心" 的。&lt;br /&gt;&lt;br /&gt;再例如: 英文的单引号会被误认为英文的撇号(apostrophe), 在 (utf8 编码的) 显示中位置不对称; 中文的双/单引号也有左右之分, 对使用软件的替换工具, 把单引号替换成中文的引号是绝对不方便。而使用英文的双引号, 就能尽量减少显示和替换的麻烦。尽管英文的双引号和单引号在软件的字符串中, 既相互交叉使用, 也有自己的含义差别。&lt;br /&gt;&lt;br /&gt;但在命令行字符串中引号不宜简单翻成中文的符号。建议此时保留英文的双引号; 而英文的单引号(')改中文的单引号(‘ ’), 同时尽量附加译者注释表示是 "英文" 的单引号。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;规则 2.&lt;/strong&gt; 按照传统的规则, 一个标点占一个中文字 (注: 一个中文字占两个字符), 但两个标点挤占一个中文字。 有时括号有例外情形。&lt;br /&gt;&lt;br /&gt;说明:&lt;br /&gt;&lt;br /&gt;既然使用英文的标点符号, 本来英文文章的标点符号后就有空格, 而中文的标点符号 (如: 句号) 一般占一个中文字。标点符号带的空格问题迎刃而解。用英文的符号和空格的另一个好处是: 字处理软件上往往是双击选取单词 (注: 英文是以英文的符号和空格来区分单词的), 碰到中文就不会选取整行了。(另外还有软件的字计数问题, 能不能计数智能一点啊。) 括号占位例外情形请参看下面的规则 2 中的建议。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;规则 3.&lt;/strong&gt; 碰到不宜翻译的词 (如: 专有名词, 术语, 翻不出来的词) 时, 应照顾读者的脑力而保留原文。&lt;br /&gt;&lt;br /&gt;示例:&lt;br /&gt;&lt;br /&gt;英文的撇号(apostrophe), 在 (utf8 编码的) 显示中位置不对称"&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3.1.&lt;/strong&gt; 只用原文时应保留前后的空格。如: 示例中的 "utf8"。&lt;br /&gt;&lt;br /&gt;说明:&lt;br /&gt;&lt;br /&gt;中英文夹杂一起时不留空格很费眼力不美观。而且几个英文词一起时, 为什么英文词是一个个的碰到中文就要粘在一起?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3.2.&lt;/strong&gt; 同时用原文和译文 (硬要翻译的话) 建议用括号括起来。如: 示例中的 "apostrophe"。&lt;br /&gt;&lt;br /&gt;说明:&lt;br /&gt;&lt;br /&gt;不管是英文加带括号的中文译文, 还是中文加带括号的英文注释, 都可以, 取决于翻译者对哪个有把握。至于此时括号外面是否要带空格? 建议不带空格, 否则变成多出来的词了。不带空格的括号中的文字表示替换前面的词, 两者只读(取)其中一个。而带空格的括号中的文字应该不管读不读出来都要能保持整句通顺。但如果是几个英文词一起的加注释中文呢? 建议尽量避免, 要么注释整句, 这样可按照一般情形带空格。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;规则 4.&lt;/strong&gt; 阿拉伯数字当作英文, 前面用空格, 后面如果跟的是单位的话可用也可不用空格。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;规则 5.&lt;/strong&gt; 建议尽量弄个术语表和用语表, 对后继译者来说能统一翻译用词, 术语表对读者也是一种尊重。 &lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15881528-116423208852647892?l=jinsh2.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinsh2.blogspot.com/feeds/116423208852647892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15881528&amp;postID=116423208852647892' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/116423208852647892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15881528/posts/default/116423208852647892'/><link rel='alternate' type='text/html' href='http://jinsh2.blogspot.com/2006/11/rules-of-translation-to-chinese-1.html' title=''/><author><name>jinsh2</name><uri>http://www.blogger.com/profile/03008969182513984433</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
