Archive for the ‘JavaScript’ Category

Open Sourcing Flash, in the pan

Wednesday, April 11th, 2007

There is some buzz about the possibility, chance and point of open sourcing Flash.

As a web-developer I tend not to use Flash. If I can implement a feature without Flash I will. If I have to use Flash I keep it minimal. If people show me full-Flash apps. I want to know why they did it in Flash. The only two places Flash truly shines in my opinion are; as a video player in web-pages ala YouTube and for small, tricky, slick controls that are too finicky to do well in JavaScript/CSS/HTML.

Why do I try not to use Flash? Because I like text and am not a binary fan. Images (JPEG, GIF and PNG) are binary but they aren’t source. They aren’t applications, they don’t contain logic or have functionality like an SWF can. I can’t view-source on an SWF easily, I can’t hack a few characters, rerun it and see the change. I can’t easily mold an existing Flash into something else.

For me this is what CSS, HTML and JavaScript do so well. You can hack them, save them, view source, pipe them through a cheese grater and get something usable on the other end. Anything you see done with them you can figure out.

So open sourcing Flash isn’t going to make me sing hallelujah and start using it. A pity but there you go.

(As for Apollo I am really, really happy it isn’t a Flash container. It is a web container, it can house CSS, JavaScript and HTML without an ounce of Flash in sight.)

Javascript code coverage MIA

Wednesday, October 4th, 2006

Code coverage tools for Javascript are thin on the ground. In fact, I have only found one - JavaScript Coverage Validator - and it isn’t even out of closed beta yet.

Am I to think that all those millions of lines of Javascript out there on all those Web 2.0 sites that espouse agile practies with TDD influences don’t have code coverage? Sure, some may have unit testing but unit testing without code coverage is a less than ideal situation. You simply don’t know if you have tested all functions and all paths in your functions. Unit testing and code coverage go hand in hand, they back each other up.

Do you have a solution to code coverage for your Javascript?

RailsConf Europe 2006: Unobtrusive Ajax with Dan Webb

Friday, September 15th, 2006

(code and slides)
Dan Webb’s Unobtrusive Ajax With Rails talk proved so popular yesterday that it is being redone in the main hall during lunch today.

Unobtrusive Ajax (or JavaScript really) is all about removing all those inline onclick=”return myFunc(an_id)” bits of code from your HTML and into your JS. Separating behaviour and mark-up. Attaching behaviour to your class definitions e.g. class=”productbutton”.

At the very least this makes your pages smaller (think of a 1000 item list which has onclicks inline vs. attached via a class in a separate JS.)

At the most it is the idea of the class assigned to HTML elements.

A big theme is graceful degredation for when JS is not available.

A good point is around a href=”#” which semantically and functionally doesn’t make sense. I am an offender here but aim to change.

button_to is a little known Rails helper that generates a button in a form. This is for when you should be using buttons and not links e.g. for delete links. Remember, links should not have side effects (if for no other practical reason than avoiding pre-fetch technologies like the Google Toolbar that will wipe your records.)

To get started with UJS checkout the Rails plugin at ujs4rails.com.

A good talk and as Dan says, it isn’t rocket science. It has obvious benefits even if you don’t care about semantics. Hopefully Rails takes the ideas into the trunk.

Functions as arguements

Friday, July 28th, 2006

Slash7 has posted the slides from their brilliant Javascript Boot Camp Tutorial talk at OSCON. 108 pages of pure JavaScript love. One thing I just learnt, on page 36, is that you can pass a function as an arguement into another function. That function can then call the arguement function. Sounds weird but that is pretty amazing if you ask me.

jQuery and GreaseMonkey

Sunday, July 23rd, 2006

jQuery is a fantastic piece of JavaScript and is fast replacing prototype in my projects. I’d like it to go beyond that though. I want it to be a library I can call on any website I am visiting, whether the site has it loaded or not.

GreaseMonkey seems the logical way to do this. I had a quick stab at loading jQuery as a user script but it didn’t seem to work.

Anybody got a clue how to do this?

Remove array item

Thursday, July 13th, 2006

I like the way you can add methods/functions/members to built in JavaScript entities. The following adds a remove method to the Array object.

Array.prototype.remove = function(item_to_remove)
{
  for (var i = 0; i < this.length; i++)
  {
    if (this[i] == item_to_remove)
    {
      this.splice(i,1);
      break;
    }
  }
}

Anybody know a better way of removing items from an array?

Namespacing JavaScript

Monday, June 19th, 2006

Snook writes about namespacing your JavaScript code and asks what standards we should adopt and the best way of doing it. It is an important topic. Afterall, we namespace our Java, C# etc. code and think it is important there.

Snook namespaces in the following way:
var snook = new Object();
snook.someFunc = function ()
{...}

snook.anotherFunc = function ()
{...}

Do you know of any other ways to namespace your JavaScript?

Functional objects

Wednesday, June 7th, 2006

It is obvious when you think about it but functions are objects in JavaScript. So a function can have members. e.g.
var f = function()
{
    return 2;
}

f.g = function(x)
{
    return x + f();
}

If I ran f.g(5); I’d get back 7.