rss

QUnit:JavaScript Testing Framework

Category : Javascript

QUnit is a powerful JavaScript unit testing framework that helps you to debug code. It’s written by members of the jQuery team, and is the official test suite for jQuery. But QUnit is general enough to test any regular JavaScript code, and it’s even able to test server-side JavaScript via some JavaScript engine like Rhino or V8.

If you’re unfamiliar with the idea of “unit testing”, don’t worry. It’s not too difficult to understand:

In computer programming, unit testing is a software verification and validation method in which a programmer tests if individual units of source code are fit for use. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual function or procedure.

This is quoted from Wikipedia. Simply put, you write tests for each functionality of your code, and if all of these tests are passed, you can be sure that the code will be bug-free (mostly, depends on how thorough your tests are).

  • Share/Bookmark

Javascript: visual event

2

Category : Javascript

When working with events in Javascript, it is often easy to loose track of what events are subscribed where. This is particularly true if you are using a large number of events, which is typical in a modern interface employing progressive enhancement. Javascript libraries also add another degree of complexity to listeners from a technical point of view, while from a developers point of view they of course can make life much easier! But when things go wrong it can be difficult to trace down why this might be.

It is due to this allan jardine put together a Javascript bookmarklet called Visual Event which visually shows the elements on a page that have events subscribed to them, what those events are and the function that the event would run when triggered. This is primarily intended to assist debugging, but it can also be very interesting and informative to see the subscribed events on other pages.

  • Share/Bookmark

PhoneGap: Cross Platform Mobile Framework

Category : Internet News, Javascript, mobile

PhoneGap is an open source development tool for building fast, easy mobile apps with JavaScript.

If you’re a web developer who wants to build mobile applications in HTML and JavaScript while still taking advantage of the core features in the iPhone, Android and Blackberry SDKs, PhoneGap is for you.

Supported Features

iPhone Android Blackberry
Geo Location yes yes yes
Vibration yes yes pending
Accelerometer yes yes pending
Sound yes yes pending
Contact Support yes pending pending

PhoneGap aims to solve device integration by web enabling devices native functionality with open standards.

Above all its totally an open source, hurray…

Here is what the creators of PhoneGap say:

  • Share/Bookmark

3D Cube using CSS transformations

Category : CSS

http://www.fofronline.com/2009-04/3d-cube-using-css-transformations/

The impression of a three dimensional cube can be created using modern CSS techniques, without the need for JavaScript, imagery, canvas or SVG. Supported in recent WebKit and Gecko based browsers, most importantly Firefox 3.5+ -moz-transform and Safari 3.2+ -webkit-transform.

  • Share/Bookmark

Decision Center for Ajax Frameworks

Category : Javascript

Briggs of Athenz has pointed his decision machine at the age old problem of choosing which darn library to choose. Now let the machine choose which library to use rather you choosing the library.

Briggs has developed an application that chooses the Framework for you.

http://www.athenz.com/app/decision/center/ajax

A collaborative decision platform that is designed to help you make better technology decisions.

A sophisticated, yet friendly decision engine to help you prioritize, compare, assess, and synthesize.

  • Share/Bookmark

YUI3 – Satyen Desai

Category : Javascript

  • Share/Bookmark

jsPDF: PDF documents using pure JavaScript

4

Category : Javascript

jsPDF is an open-source library for generating PDF documents using nothing but Javascript. You can use it in a Firefox extension, in Server Side Javascript and with Data URIs in some browsers.

See Demo

Client-side demo works best in Safari or iPhone Safari. Also works Firefox 3 on Windows and Opera. IE support on the way.
Server-side should work anywhere. Examples soon.

  • Share/Bookmark

Javascript: Ways to iterate over an array

Category : General

for each in:

JAVASCRIPT:

  1. for each (var item in [1, 2, 3]) alert(item);

JavaScript 1.6 added the Array.forEach method:

JAVASCRIPT:

  1. [1, 2, 3].forEach(function(item) { alert(item) });

JavaScript 1.7 added array comprehensions for array initialization:

JAVASCRIPT:

  1. var squares = [item * item for each (item in [1, 2, 3])];

I just realized I can (ab)use comprehensions to iterate arrays with Perl-like syntax by throwing away the result:

JAVASCRIPT:

  1. [alert(item) for each (item in [1, 2, 3])];

I can iterate object properties the same way:

JAVASCRIPT:

  1. var obj = { foo: 1, bar: 2, baz: 3 };
  2. [alert(name + "=" + obj[name]) for (name in obj)];

Edward Lee points out how to use Iterators:

JAVASCRIPT:

  1. [alert(key + "=" + val) for ([key, val] in Iterator({a:1,b:2,c:3}))]
  • Share/Bookmark

Using JQuery & Prototype together

Category : Javascript

You would surely have used JQuery and Prototype for dynamic web applications like Lightview, Prototip, etc. Here i would show you how to user them two together, on the same page.

Problem
The Problem JQuery uses a “$” as a shortcut for “jQuery” and Prototype uses “$” as well. We can’t have JQuery and Prototype using the same “$” namespace.

The Fix
Thankfully JQuery has a neat little function called jQuery.noConflict( ) which you basically just need to stick at the top of your JQuery file and replace the “$” alias with “jQuery” for each function. Example:

jQuery.noConflict();
// Do something with jQuery
jQuery(“div p”).hide();
// Do something with another library’s $()
$(“content”).style.display = ‘none’;

Of course, there are other ways of solving this issue with jQuery.noConflict( )

NOTE: JQuery doesn’t get along with MooTools and YUI very well either, luckily this can also be solved with the jQuery.noConflict( ) trick.

  • Share/Bookmark

Javascript Best Practices

Category : Javascript

  • Share/Bookmark

Amit Yadav is Digg proof thanks to caching by WP Super Cache