JavaScript Enlightenment | by Cody Lindley | 1st Edition | ECMA-262, Edition 3 AlexNogard : Tutos IT Linux : Supervision : Centreon, Nagios, Owncloud; Windows Server 2012 : Hyper-V 3 Writing Jasmine unit tests in ES6 Previously I showed how to write application code using ES6, but wouldn't it be nice to use ES6 when writing unit tests as well? In the following post I will demonstrate how to write Jasmine tests using ES6 syntax. Setting up the test environment is fairly easy, but to move things along I've included my sample package.json configuration package.json I will be using Karma to run the tests, so the next step is to add a karma.config.js file to your project. karma.config.js I have chosen to run my tests using PhantomJS – a headless browser ideal for these types of tasks. Babel is used for transpiling ES6 to ES5. The last bit of plumbing is to add test-context.js to your project: test-context.js var context = require.context('. This is where you tell the test runner where your files are located. context.keys contains an array of test files. Now that the environment is bootstrapped it's time to write some tests! To keep it simple we will be writing tests for a simple calculator implementation. Sources
JavaScript Garden Although JavaScript deals fine with the syntax of two matching curly braces for blocks, it does not support block scope; hence, all that is left in the language is function scope. function test() { // a scope for(var i = 0; i < 10; i++) { // not a scope // count } console.log(i); // 10} There are also no distinct namespaces in JavaScript, which means that everything gets defined in one globally shared namespace. Each time a variable is referenced, JavaScript will traverse upwards through all the scopes until it finds it. In the case that it reaches the global scope and still has not found the requested name, it will raise a ReferenceError. The Bane of Global Variables // script Afoo = '42'; // script Bvar foo = '42' The above two scripts do not have the same effect. Again, that is not at all the same effect: not using var can have major implications. // global scopevar foo = 42;function test() { // local scope foo = 21;}test();foo; // 21 Local Variables var foo = 3; bar = 4;}test(10); Hoisting
Voyage au coeur de JavaScript (ECMAScript 3) Cet article est une traduction de JavaScript. The Core écrit par Dmitry Soshnikov. Javascript The Core est un sommaire détaillé de la série d’article “ECMA-262-3 in detail”. Commençons par étudier le concept d'objet, un fondamental d'ECMAScript. L'objet ECMAScript étant un langage orienté objet de haut niveau, il fonctionne avec des objets. Un objet est une collection de propriétés qui possède un unique objet prototype. Prenons pour exemple un objet simple. Cet objet possède deux propriétés explicitement déclarées et une propriété __proto__ implicite qui est une référence au prototype de foo: Mais pourquoi ces prototypes sont-ils requis ? Le chaînage des prototypes Les prototypes sont des objets comme les autres et peuvent posséder leurs propres prototypes. Une chaîne de prototype est une chaîne finie d'objet utilisé pour implémenter l'héritage et le partage de propriétés. Examinons le cas où nous avons deux objets qui diffèrent sensiblement. ECMAScript ne possède pas de concept de classe.
ECMAScript 6: New Features: Overview and Comparison "A good programming language is a conceptual universe for thinking about programming." — Alan J. Perlis Constants Support for constants (also known as "immutable variables"), i.e., variables which cannot be re-assigned new content. Notice: this only makes the variable itself immutable, not its assigned content (for instance, in case the content is an object, this means the object itself can still be altered). ECMAScript 6 — syntactic sugar: reduced | traditional const PI = 3.141593; PI > 3.0; ECMAScript 5 — syntactic sugar: reduced | traditional Scoping Block-Scoped Variables Block-scoped variables (and constants) without hoisting. for (let i = 0; i < a.length; i++) { let x = a[i]; …}for (let i = 0; i < b.length; i++) { let y = b[i]; …} let callbacks = [];for (let i = 0; i <= 2; i++) { callbacks[i] = function () { return i * 2; };} callbacks[0]() === 0; callbacks[1]() === 2; callbacks[2]() === 4; Block-Scoped Functions Block-scoped function definitions. Arrow Functions Expression Bodies Lexical this
JavaScript Succinctly JavaScript Succinctly was written to give readers an accurate, concise examination of JavaScript objects and their supporting nuances, such as complex values, primitive values, scope, inheritance, the head object, and more. If you’re an intermediate JavaScript developer and want to solidify your understanding of the language, or if you’ve only used JavaScript beneath the mantle of libraries such as jQuery or Prototype, this is the book for you. Author Cody Lindley talks about his latest book in Syncfusion's Succinctly series, JavaScript Succinctly. Given his many years of expertise and the overwhelming success of this last publication—jQuery Succinctly—what Cody says about JavaScript is something all experienced frontend developers should take to heart.
Javascript quiz I was recently reminded about Dmitry Baranovsky's Javascript test, when N. Zakas answered and explained it in a blog post. First time I saw those questions explained was by Richard Cornford in comp.lang.javascript, although not as thoroughly as by Nicholas. I decided to come up with my own little quiz. Host objects Contrary to Dmitry's test, quiz does not involve host objects (e.g. window), as their behavior is unspecified and can vary sporadically across implementations. So what are we testing? Not a lot really. Note, however, that not all questions are very practical, so don't worry if you can't answer some of them. Few notes about code Quiz Please make sure you select answer in each question, as lack of answer is not checked and counts as failure. I hope you liked it.
Raynos/chain-stream Book of Modern Front-end Tooling You Might Not Need jQuery