background preloader

Javascript

Facebook Twitter

Js-testing

Organize Your Code with RequireJS. Writing web applications using JavaScript, HTML, and CSS can become overwhelming quickly. Between managing UI, data, interactions, and network requests, application code can become a real mess, and this isn’t helped by the way the browser loads JavaScript code. In most other programming environments, there is some way to split your code into modules or scripts, and specifically require one module from another. In JavaScript, we can split our code into multiple files, but there is no way to declare in one script that you are depending on another. Worse yet, the place where scripts are loaded isn’t even in the same language you are writing your code.

You load all your JavaScript dependencies from your HTML document, not your JavaScript files. I have had the opportunity to work on a large single page application for Treehouse, and tried using RequireJS, and I love it. How does RequireJS make building an application easier? Module Definition A typical simple module is defined like this: Retrieve Unique Values from an Array with JavaScript. Delegation vs Inheritance in JavaScript | JavaScript, JavaScript. When asked what he might do differently if he had to rewrite Java from scratch, James Gosling suggested that he might do away with class inheritance and write a delegation only language. Using inheritance as a vehicle for code reuse is a bit like ordering a happy meal because you wanted the plastic toy.

Sure a circle is a shape and a dog is a mammal – but once we get past those textbook examples most of our hierarchies get arbitrary and tenuous – built for manipulating behaviour even as we pretend we are representing reality. Successive descendants are saddled with an ever increasing number of unexpected or irrelevant behaviours for the sake of re-using a few. Delegation is a technique that promotes code reuse by allowing runtime function invocation in the context of a specific instance – regardless of the hierarchical lineage of instance and function.

I’m going to demonstrate, by way of a use case, how call and apply can promote a clean, functional approach code to re-use. Wrap Up. Test-Driven JavaScript Development in Practice. TDD is an iterative development process where each iteration starts by writing a test which forms a part of the specification we are implementing. The short iterations allow for more instant feedback on the code we are writing, and bad design decisions are easier to catch. By writing the tests prior to any production code, good unit test coverage comes with the territory, but that is merely a welcome side-effect. Republished Tutorial Every few weeks, we revisit some of our reader's favorite posts from throughout the history of the site. This tutorial was first published in November of 2010. Turning Development Upside-Down In traditional programming, problems are solved by programming until a concept is fully represented in code. Test-driven development turns the development cycle upside-down.

The Process The test-driven development process is an iterative process where each iteration consists of the following four steps: In each iteration, the test is the specification. Adding Observers. Test-Driven JavaScript Development in Practice.

Jquery

Javascript framework.