background preloader

Javascript

Facebook Twitter

Js-testing

Organize Your Code with RequireJS. 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.