仿QQ音乐的微信小程序的设计与实现外文翻译资料

 2021-12-14 10:12

  1. Michael Fogus, Introducing Functional JavaScript, Chapter 1 ,《Functional JavaScript》,Orsquo;Reilly

1、英语原文

This chapter sets up the book in a number of important ways. In it, I will introduce Underscore and explain how you can start using it. Additionally, I will define the terms and goals of the rest of the book.

1. The Case for JavaScript

The question of why you might choose JavaScript is easily answered in a word: reach. In other words, aside from perhaps Java, there is no more popular programming lan‐ guage right now than JavaScript. Its ubiquity in the browser and its near-ubiquity in a vast sea of current and emerging technologies make it a nice—and sometimes the only—choice for portability.

With the reemergence of client-service and single-page application architectures, the use of JavaScript in discrete applications (i.e., single-page apps) attached to numerous network services is exploding. For example, Google Apps are all written in JavaScript, and are prime examples of the single-page application paradigm.

If yoursquo;ve come to JavaScript with a ready interest in functional programming, then the good news is that it supports functional techniques “right out of the box” (e.g., the function is a core element in JavaScript). For example, if you have any experience with JavaScript, then you might have seen code like the following:

[1, 2, 3].forEach(alert);

// alert box with '1' pops up

// alert box with '2' pops up

// alert box with '3' pops up

The Array#forEach method, added in the fifth edition of the ECMA-262 language standard, takes some function (in this case, alert) and passes each array element to the function one after the other. That is, JavaScript provides various methods and functions that take other functions as arguments for some inner purpose. Irsquo;ll talk more about this style of programming as the book progresses.

JavaScript is also built on a solid foundation of language primitives, which is amazing, but a double-edged sword (as Irsquo;ll discuss soon). From functions to closures to prototypes to a fairly nice dynamic core, JavaScript provides a well-stocked set of tools. In addition, JavaScript provides a very open and flexible execution model. As a small example, all JavaScript functions have an apply method that allows you to call the function with an array as if the array elements were the arguments to the function itself. Using apply, I can create a neat little function named splat that just takes a function and returns another function that takes an array and calls the original with apply, so that its elements serve as its arguments:

function splat(fun) { return function(array) { return fun.apply(null, array); }; }

var addArrayElements = splat(function(x, y) { return x y });

addArrayElements([1, 2]); //=gt; 3

This is your first taste of functional programming—a function that returns another function—but Irsquo;ll get to the meat of that later. The point is that apply is only one of many ways that JavaScript is a hugely flexible programming language.

Another way that JavaScript proves its flexibility is that any function may be called with any number of arguments of any type, at any time. We can create a function unsplat that works opposite from splat, taking a function and returning another function that takes any number of arguments and calls the original with an array of the values given:

function unsplat(fun) { return function() { return fun.call(null, _.toArray(arguments)); }; }

var joinElements = unsplat(function(array) { return array.join(#39; #39;) });

joinElements(1, 2); //=gt; '1 2'

joinElements(#39;-#39;, #39;$#39;, #39;/#39;, #39;!#39;, #39;:#39;); //=gt; '- $ / ! :'

Every JavaScript function can access a local value named arguments that is an array- like structure holding the values that the function was called with. Having access to arguments is surprisingly powerful, and is used to amazing effect in JavaScript in the wild. Additionally, the call method is similar to apply except that the former takes the arguments one by one rather than as an array, as expected by apply. The trifecta of apply, call, and arguments is only a small sample of the extreme flexibility provided by JavaScript.

With the emergent growth of JavaScript for creating applications of all sizes, you might expect stagnation in the language itself or its runtime support. However, even a casual investigation of the ECMAScript.next initiative shows that itrsquo;s clear that JavaScript is an evolving (albeit slowly) language. Likewise, JavaScript engines like V8 are constantly evolving and improving JavaScript speed and efficiency using both time-tested and novel techniques.

2. Some Limitations of JavaScript

The case against JavaScript—in light of its evolution, ubiquity, and reach—is quite thin. You can say much about the language quirks and robustness failings, but the fact is that JavaScript is here to stay, now and indefinitely. Regardless, itrsquo;s worth acknowledging that JavaScript is a flawed language. In fact, the most popular book on JavaScript, Douglas Crockfordrsquo;s JavaScript: The Good Parts (Orsquo;Reilly), spends more pages discus‐ sing the terrible parts than the good. The language has true oddities, and by and large is not particularly succinct in expression. However, changing the problems with Java‐ Script would likely “break the Web,” a circumstance thatrsquo;s unacceptable to most. Itrsquo;s because of these problems that the number of

资料编号:[5318]

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。