翻譯 Secrets of the JavaScript Ninja 邊譯邊學(12)

Secrets of the JavaScript Ninja 邊譯邊學(12)第3.1節 函數的區別是什麼?

3.1 What’s with the functional difference?
3.1 函數的區別是什麼?

How many times have you heard someone moan “I hate JavaScript!”?
你聽到過多少次有人抱怨“我討厭JavaScript!”?

  We’re willing to bet that nine times out of ten (or perhaps even greater), this is a direct consequence of someone trying to use JavaScript as if it were another language that the lamenter is more familiar with, and frustrated by the fact that it’s not that other language.
  我敢打賭,以上的抱怨十有八九來自那些將JavaScript當作另外一種語言來使用的人,這些可憐的人將JavaScript當作他熟悉的語言,最終只能爲JavaScript不是另一種語言這一事實而感到沮喪。

  This is probably most common with those coming to JavaScript from a language such as Java, a decidedly non-functional language, but one that a lot of developers learn before their exposure to JavaScript.
  這種情況普遍存在於那些由一種明確的非功能性語言比如Java轉向JavaScript語言開發者身上,但很多開發人員在接觸到JavaScript之前就已經瞭解到了這一點。

  Making matters even worse for these developers is the unfortunate naming choice of JavaScript. Without belaboring the history behind that lamentable naming decision, perhaps developers would have fewer incorrect preconceived notions about JavaScript if it had retained the name LiveScript or been given some other less confounding name.
  更糟糕的是,該語言命名爲JavaScript。現在拋開對這個可悲的命名決策的討論,如果該語言一開始命名爲LiveScript或者其他不會造成這麼多歧義的名字,可能開發者們對JavaScript就不會有這麼多錯誤的預設了。

  Because JavaScript, as the old joke depicted in figure 3.1 goes, has as much to do with Java as a hamburger has to do with ham.
  因爲JavaScript和Java的關係就像漢堡和火腿的關係一樣,正如圖片3.1中描繪的一個古老的的玩笑:

  Hamburgers and ham are both foods that are meat products, just as JavaScript and Java are both programming languages with a C-influenced syntax, but other than that, they don’t have much in common, and are fundamentally different right down to their DNA.
  漢堡和火腿都是食物而且都是肉類加工食物,正如JavaScript和Java都是C風格的編程語言,但除了這點,它們沒什麼共同點,而且從骨子裏是完全不同的。

NOTE

Another factor that plays into some developers’ poor initial reaction to JavaScript may be that most developers are introduced to JavaScript in the browser. So rather than reacting to JavaScript, The Language, they may be recoiling from the JavaScript bindings to the DOM API. And the DOM API… well, let’s just say that it isn’t going to win any Friendliest API of the Year awards. But that’s not JavaScript’s fault.

注意

另一個造成一些開發人員對javascript最初反應不佳的因素可能是大多數開發人員都是在瀏覽器中初次接觸JavaScript。 所以人們通常將它當作是一種DOM API,而不是JavaScript-一種編程語言。 dom api……好吧,讓我們假設它不會贏得任何*“年度最友好的api”*獎項。 但那確實不是JavaScript的錯。

  Before we learn about how functions are such a central and key concept in JavaScript, let’s understand why the functional nature of JavaScript is so important, especially for code written for the browser.
  在我們瞭解函數是如何成爲JavaScript中的核心和關鍵概念之前,讓我們先了解一下爲什麼JavaScript的功能性質如此重要,特別是對於爲瀏覽器編寫的代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章