




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、word 畢 業(yè) 設(shè) 計(jì)論文外 文 文 獻(xiàn) 翻 譯文獻(xiàn)、資料中文題目:JavaScript文獻(xiàn)、資料英文題目:JavaScript文獻(xiàn)、資料來(lái)源:文獻(xiàn)、資料發(fā)表出版日期:院 部: 專(zhuān) 業(yè): 班 級(jí): 姓 名: 學(xué) 號(hào): 指導(dǎo)教師: 翻譯日期: JavaScriptWhen I was a young journeyman programmer, I would learn about every feature of the languages I was using, and I would attempt to use all of those features when I wrote.
2、 I suppose it was a way of showing off, and I suppose it worked because I was the guy you went to if you wanted to know how to use a particular feature.Eventually I figured out that some of those features were more trouble than they were worth. Some of them were poorly specified, and so were more li
3、kely to cause portability problems. Some resulted in code that was difficult to read or modify. Some induced me to write in a manner that was too tricky and error-prone. And some of those features were design errors. Sometimes language designers make mistakes.Most programming languages contain good
4、parts and bad parts. I discovered that I could be a better programmer by using only the good parts and avoiding the bad parts. After all, how can you build something good out of bad partsIt is rarely possible for standards committees to remove imperfections from a language because doing so would cau
5、se the breakage of all of the bad programs that depend on those bad parts. They are usually powerless to do anything except heap more features on top of the existing pile of imperfections. And the new features do not always interact harmoniously, thus producing more bad parts.But you have the power
6、to define your own subset. You can write better programs by relying exclusively on the good parts.JavaScript is a language with more than its share of bad parts. It went from non-existence to global adoption in an alarmingly short period of time. It never had an interval in the lab when it could be
7、tried out and polished. It went straight into Netscape Navigator 2 just as it was, and it was very rough. When Java applets failed, JavaScript became the "Language of the Web" by default. JavaScript's popularity is almost completely independent of its qualities as a programming languag
8、e.Fortunately, JavaScript has some extraordinarily good parts. In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders. The best nature of JavaScript is so effectively hidden that for many years the prevailing opin
9、ion of JavaScript was that it was an unsightly, incompetent toy. My intention here is to expose the goodness in JavaScript, an outstanding, dynamic programming language. JavaScript is a block of marble, and I chip away the features that are not beautiful until the language's true nature reveals
10、itself. I believe that the elegant subset I carved out is vastly superior to the language as a whole, being more reliable, readable, and maintainable.This book will not attempt to fully describe the language. Instead, it will focus on the good parts with occasional warnings to avoid the bad. The sub
11、set that will be described here can be used to construct reliable, readable programs small and large. By focusing on just the good parts, we can reduce learning time, increase robustness, and save some trees.Perhaps the greatest benefit of studying the good parts is that you can avoid the need to un
12、learn the bad parts. Unlearning bad patterns is very difficult. It is a painful task that most of us face with extreme reluctance. Sometimes languages are subsetted to make them work better for students. But in this case, I am subsetting JavaScript to make it work better for professionals.Why JavaSc
13、riptJavaScript is an important language because it is the language of the web browser. Its association with the browser makes it one of the most popular programming languages in the world. At the same time, it is one of the most despised programming languages in the world. The API of the browser, th
14、e Document Object Model (DOM) is quite awful, and JavaScript is unfairly blamed. The DOM would be painful to work with in any language. The DOM is poorly specified and inconsistently implemented. This book touches only very lightly on the DOM. I think writing a Good Parts book about the DOM would be
15、 extremely challenging.JavaScript is most despised because it isn't SOME OTHER LANGUAGE. If you are good in SOME OTHER LANGUAGE and you have to program in an environment that only supports JavaScript, then you are forced to use JavaScript, and that is annoying. Most people in that situation don&
16、#39;t even bother to learn JavaScript first, and then they are surprised when JavaScript turns out to have significant differences from the SOME OTHER LANGUAGE they would rather be using, and that those differences matter.The amazing thing about JavaScript is that it is possible to get work done wit
17、h it without knowing much about the language, or even knowing much about programming. It is a language with enormous expressive power. It is even better when you know what you're doing. Programming is difficult business. It should never be undertaken in ignorance.Analyzing JavaScriptJavaScript i
18、s built on some very good ideas and a few very bad ones.The very good ideas include functions, loose typing, dynamic objects, and an expressive object literal notation. The bad ideas include a programming model based on global variables.JavaScript's functions are first class objects with (mostly
19、) lexical scoping. JavaScript is the first lambda language to go mainstream. Deep down, JavaScript has more in common with Lisp and Scheme than with Java. It is Lisp in C's clothing. This makes JavaScript a remarkably powerful language.The fashion in most programming languages today demands stro
20、ng typing. The theory is that strong typing allows a compiler to detect a large class of errors at compile time. The sooner we can detect and repair errors, the less they cost us. JavaScript is a loosely typed language, so JavaScript compilers are unable to detect type errors. This can be alarming t
21、o people who are coming to JavaScript from strongly typed languages. But it turns out that strong typing does not eliminate the need for careful testing. And I have found in my work that the sorts of errors that strong type checking finds are not the errors I worry about. On the other hand, I find l
22、oose typing to be liberating. I don't need to form complex class hierarchies. And I never have to cast or wrestle with the type system to get the behavior that I want.JavaScript has a very powerful object literal notation. Objects can be created simply by listing their components. This notation
23、was the inspiration for JSON, the popular data interchange format. A controversial feature in JavaScript is prototypal inheritance. JavaScript has a class-free object system in which objects inherit properties directly from other objects. This is really powerful, but it is unfamiliar to classically
24、trained programmers. If you attempt to apply classical design patterns directly to JavaScript, you will be frustrated. But if you learn to work with JavaScript's prototypal nature, your efforts will be rewarded.JavaScript is much maligned for its choice of key ideas. For the most part, though, t
25、hose choices were good, if unusual. But there was one choice that was particularly bad: JavaScript depends on global variables for linkage. All of the top-level variables of all compilation units are tossed together in a common namespace called the global object. This is a bad thing because global v
26、ariables are evil, and in JavaScript they are fundamental. Fortunately, as we will see, JavaScript also gives us the tools to mitigate this problem.In a few cases, we can't ignore the bad parts. There are some unavoidable awful parts, which will be called out as they occur. They will also be sum
27、marized in Appendix A. But we will succeed in avoiding most of the bad parts in this book, summarizing much of what was left out in Appendix B. If you want to learn more about the bad parts and how to use them badly, consult any other JavaScript book.The standard that defines JavaScript (aka JScript
28、) is the third edition of The ECMAScript Programming Language. The language described in this book is a proper subset of ECMAScript. This book does not describe the whole language because it leaves out the bad parts. The treatment here is not exhaustive. It avoids the edge cases. You should, too. Th
29、ere is danger and misery at the edges.A JavaScript parser that can analyze a JavaScript program and report on the bad parts that it contains. JSLint provides a degree of rigor that is generally lacking in JavaScript development. It can give you confidence that your programs contain only the good par
30、ts.JavaScript is a language of many contrasts. It contains many errors and sharp edges, so you might wonder, "Why should I use JavaScript" There are two answers. The first is that you don't have a choice. The Web has become an important platform for application development, and JavaScr
31、ipt is the only language that is found in all browsers. It is unfortunate that Java failed in that environment; if it hadn't, there could be a choice for people desiring a strongly typed classical language. But Java did fail and JavaScript is flourishing, so there is evidence that JavaScript did
32、 something right.The other answer is that, despite its deficiencies, JavaScript is really good. It is lightweight and expressive. And once you get the hang of it, functional programming is a lot of fun.But in order to use the language well, you must be well informed about its limitations. I will pou
33、nd on those with some brutality. Don't let that discourage you. The good parts are good enough to compensate for the bad parts.StyleComputer programs are the most complex things that humans make. Programs are made up of a huge number of parts, expressed as functions, statements, and expressions
34、that are arranged in sequences that must be virtually free of error. The runtime behavior has little resemblance to the program that implements it. Software is usually expected to be modified over the course of its productive life. The process of converting one correct program into a different corre
35、ct program is extremely challenging.Good programs have a structure that anticipatesbut is not overly burdened bythe possible modifications that will be required in the future. Good programs also have a clear presentation. If a program is expressed well, then we have the best chance of being able to
36、understand it so that it can be successfully modified or repaired.These concerns are true for all programming languages, and are especially true for JavaScript. JavaScript's loose typing and excessive error tolerance provide little compile-time assurance of our programs' quality, so to compe
37、nsate, we should code with strict discipline.JavaScript contains a large set of weak or problematic features that can undermine our attempts to write good programs. We should obviously avoid JavaScript's worst features. Surprisingly, perhaps, we should also avoid the features that are often usef
38、ul but occasionally hazardous. Such features are attractive nuisances, and by avoiding them, a large class of potential errors is avoided.The long-term value of software to an organization is in direct proportion to the quality of the codebase. Over its lifetime, a program will be handled by many pa
39、irs of hands and eyes. If a program is able to clearly communicate its structure and characteristics, it is less likely to break when it is modified in the never-too-distant future.JavaScript code is often sent directly to the public. It should always be of publication quality. Neatness counts. By w
40、riting in a clear and consistent style, your programs become easier to read.Programmers can debate endlessly on what constitutes good style. Most programmers are firmly rooted in what they're used to, such as the prevailing style where they went to school, or at their first job. Some have had pr
41、ofitable careers with no sense of style at all. Isn't that proof that style doesn't matter And even if style doesn't matter, isn't one style as good as any otherIt turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading.
42、JavaScript當(dāng)我還是一個(gè)初級(jí)程序員的時(shí)候,我想了解全部用到的語(yǔ)言的特點(diǎn)。 我寫(xiě)程序的時(shí)候會(huì)嘗試著去應(yīng)用所有的特性。我覺(jué)得這是炫耀的好方法,而我也確實(shí)得到了很多的榮耀,因?yàn)槲覍?duì)每個(gè)特性都非常的了解,每個(gè)人的問(wèn)題我都能夠解答。最終,我發(fā)現(xiàn)這些特性中有一局部帶來(lái)的麻煩遠(yuǎn)遠(yuǎn)大于它們的價(jià)值。其中,一些特性是因?yàn)闃?biāo)準(zhǔn)很不完整的原因,因而可能會(huì)導(dǎo)致可移植性的問(wèn)題;一些特性會(huì)導(dǎo)致產(chǎn)生很難理解和修改的代碼;一些特性使我們的代碼風(fēng)格過(guò)于復(fù)雜而且且很容易出錯(cuò);還有一些特性就是設(shè)計(jì)的錯(cuò)誤。大多數(shù)編程語(yǔ)言都有精華局部和雞肋局部。我發(fā)現(xiàn)如果只使用精華局部而防止使用雞肋的局部這樣可以使我成為一名更好的程序員。畢竟,
43、用糟糕的部件怎么可能建出好的東西?標(biāo)準(zhǔn)委員會(huì)想要移除一門(mén)語(yǔ)言中的缺陷局部,這幾乎是不可能的,因?yàn)檫@樣做會(huì)損害所有依賴(lài)于那些局部的程序。除了在已存在的一大堆缺陷上堆積更多的特性,他們通常無(wú)能為力。并且新舊特性并不總是能和諧共處??赡軓亩a(chǎn)生出更多的局部。但是,你有權(quán)力定義你自己的子集。你完全可以基于精華局部去編寫(xiě)更好的程序。JavaScript中雞肋局部的超出了預(yù)料。在短到令人吃驚的時(shí)間里,它從存在開(kāi)展到全球采用。它從來(lái)沒(méi)有在實(shí)驗(yàn)室里被試用和打磨。當(dāng)它還非常粗糙時(shí),它就被直接集成到網(wǎng)景的Navigator 2瀏覽器中。隨著Java的小應(yīng)用程序的失敗,JavaScript變成了默認(rèn)的網(wǎng)頁(yè)語(yǔ)言。作為
44、一門(mén)編程語(yǔ)言,JavaScript的流行幾乎完全不受它的質(zhì)量的影響。好在JavaScript有一些非常精華的局部。在JavaScript中,美麗的、優(yōu)雅的、富有表現(xiàn)力的語(yǔ)言特性就像一些好的東西和一些不好的東西混在一起。JavaScript最本質(zhì)的局部被常常地隱藏著,以至于多年來(lái)對(duì)它的主流觀點(diǎn)是:JavaScript就是一個(gè)丑陋的、沒(méi)用的東西。本書(shū)的目的就是要提示JavaScript中的精華,讓大家知道它是一門(mén)杰出的動(dòng)態(tài)編程語(yǔ)言。JavaScript就像是一塊大理石,我要切除那些不好的特性直到這門(mén)語(yǔ)言的真實(shí)的本質(zhì)自我顯露出來(lái)。我相信我精雕細(xì)琢出來(lái)的優(yōu)秀的一小局部大大地優(yōu)于這門(mén)語(yǔ)言的整體,它更可靠
45、、更易讀、更易于維護(hù)。我它將專(zhuān)注在精華局部上,同時(shí)會(huì)偶樂(lè)警告要去防止雞肋的局部。這里將被描述的那局部可以用來(lái)構(gòu)造可靠的、易讀取的程序。通過(guò)僅專(zhuān)注于精華局部,我們就可以縮短學(xué)習(xí)時(shí)間,增強(qiáng)健壯性,并且還能拯救一些東西?;蛟S只學(xué)習(xí)精華局部的最大好處就是你可以不用考慮的局部。忘掉不好的模式是非常困難的。這是一個(gè)非常痛苦的工作,我們中的大多數(shù)人都很不愿意面對(duì)。有時(shí)候,制定語(yǔ)言的子集是為了讓學(xué)生更好地學(xué)習(xí)。但在這里,我的JavaScript子集是為了讓專(zhuān)業(yè)人員更好了工作。為什么要使用JavaScriptJavaScript是一門(mén)重要的語(yǔ)言原因是它是web瀏覽器的語(yǔ)言。它與瀏覽器的結(jié)合使它成為世界上最流行的
46、編程語(yǔ)言之一。同時(shí),它也是世界上最被輕視的編程語(yǔ)言之一。瀏覽器的API和文檔對(duì)象模型相當(dāng)糟糕,導(dǎo)致JavaScript受到不公平的指責(zé)。在任何語(yǔ)言中處理DOM都是一件痛苦的事情,它的標(biāo)準(zhǔn)制定得很拙劣并且實(shí)現(xiàn)互不一致。JavaScript是最被輕視的語(yǔ)言,因?yàn)樗皇撬^的主流語(yǔ)言。如果你擅長(zhǎng)某些主流語(yǔ)言,但卻在一個(gè)只能支持JavaScript的環(huán)境中編程,那么被迫使用JavaScript確是相當(dāng)令人厭煩的事情。在那樣的情形下,大多數(shù)人覺(jué)得沒(méi)被要去學(xué)好JavaScript,但結(jié)果他們會(huì)驚訝地發(fā)現(xiàn),JavaScript跟他們寧愿使用的主流語(yǔ)言有很大不同,而且這些不同點(diǎn)極為關(guān)鍵。JavaScript令
47、人驚異的事情是,在對(duì)這門(mén)語(yǔ)言不太了解的情況下,甚至對(duì)編程都沒(méi)有太多了解的情況下,你也可以用它來(lái)完成工作。編程是很困難的事情,絕對(duì)不應(yīng)該在對(duì)一點(diǎn)都不了解時(shí)就開(kāi)始工作。分析JavaScriptJavaScript建立在一些非常好的想法和少數(shù)非常壞的想法之上。那些非常好的想法包括函數(shù)、弱類(lèi)型、動(dòng)態(tài)對(duì)象和一個(gè)富有表現(xiàn)力的對(duì)象字面量表示法。那些壞的想法包括基于全局變量的編程模型。JavaScript的函數(shù)是基于詞法作用域的頂級(jí)對(duì)象。JavaScript是第一個(gè)成為主流語(yǔ)言。實(shí)際上相對(duì)Java而言,JavaScript與Lisp和Scheme有更多的共同點(diǎn)。它是披著C外衣的lisp。這使得JavaScri
48、pt成為一個(gè)非常強(qiáng)大的語(yǔ)言。現(xiàn)今大多數(shù)編程語(yǔ)言中都要求強(qiáng)類(lèi)型。其原因在于強(qiáng)類(lèi)型允許編譯器在編譯時(shí)就檢測(cè)錯(cuò)誤。我們能越早檢測(cè)和更改錯(cuò)誤,損失就會(huì)越小。JavaScript是一門(mén)弱類(lèi)型的語(yǔ)言,所以JavaScript編譯器不能檢測(cè)和修改錯(cuò)誤,這可能讓從強(qiáng)類(lèi)型語(yǔ)言轉(zhuǎn)向JavaScript的開(kāi)發(fā)人員感到驚恐。但事實(shí)證明,強(qiáng)類(lèi)型并不會(huì)讓你的測(cè)試工作變得輕松。并且我在工作中發(fā)現(xiàn),強(qiáng)類(lèi)型檢查找到的那些錯(cuò)誤并不是令我頭痛的錯(cuò)誤。另一方面,我發(fā)現(xiàn)弱類(lèi)型自由的。我無(wú)須建立復(fù)雜的類(lèi)層次,我永遠(yuǎn)不用做強(qiáng)制造型,也不用很難應(yīng)付類(lèi)型系統(tǒng)以得到想得到的行為。JavaScript有非常強(qiáng)的對(duì)象字面量表示法。通過(guò)列出對(duì)象的組成局部,它們就能簡(jiǎn)單地被創(chuàng)立出來(lái)。這種表示法是促使我創(chuàng)立的數(shù)據(jù)交換格式的靈感。原型繼承是JavaScript中一個(gè)有爭(zhēng)議的特性。JavaScript有一個(gè)無(wú)類(lèi)別的對(duì)象系統(tǒng),在這個(gè)系統(tǒng)中,對(duì)象直接從其他對(duì)象繼承屬性。這真的很強(qiáng)大,但是對(duì)那些被訓(xùn)練使用類(lèi)去創(chuàng)立對(duì)象的程序員們說(shuō),原型繼承是一個(gè)陌生的概念。如果你嘗試對(duì)JavaScript的原型本質(zhì),那么你的努力將會(huì)有
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國(guó)小程序游戲行業(yè)發(fā)展現(xiàn)狀、市場(chǎng)運(yùn)行態(tài)勢(shì)及發(fā)展前景預(yù)測(cè)報(bào)告
- 七年級(jí)下冊(cè)《平行線的性質(zhì)》課件與練習(xí)
- 企業(yè)知識(shí)共享結(jié)構(gòu)優(yōu)化與創(chuàng)新能力提升
- 2025年武器、彈藥及其零件合作協(xié)議書(shū)
- 智慧城市數(shù)據(jù)平臺(tái)建設(shè)合作協(xié)議
- 電梯安裝安全協(xié)議書(shū)
- 消防安全技術(shù)服務(wù)項(xiàng)目合同
- 林地合作經(jīng)營(yíng)合同書(shū)
- 用美術(shù)相關(guān)知識(shí)做
- 古代詩(shī)詞鑒賞征文
- 幼兒園招生工作技巧培訓(xùn)
- 疼痛的護(hù)理講課課件
- 科技公司績(jī)效薪酬管理制度
- 2024年廣東省公務(wù)員考試《行測(cè)》真題及答案解析
- 上海市2024年中考化學(xué)真題(含答案)
- 門(mén)窗安裝師傅簽免責(zé)協(xié)議書(shū)范文
- 短暫性腦缺血發(fā)作護(hù)理查房
- 油氣儲(chǔ)運(yùn)節(jié)能優(yōu)化方案
- 浙江省Z20聯(lián)盟(名校新高考研究聯(lián)盟)2024屆高三下學(xué)期第三次聯(lián)考英語(yǔ)試題 含答案
- 2024-2025學(xué)年初中體育與健康七年級(jí)全一冊(cè)(2024)人教版(2024)教學(xué)設(shè)計(jì)合集
- 第五單元《分?jǐn)?shù)的意義》復(fù)習(xí)試題(單元測(cè)試)-2024-2025學(xué)年五年級(jí)上冊(cè)數(shù)學(xué)北師大版
評(píng)論
0/150
提交評(píng)論